use 数据库
go
create table DemoTable--创建表
(
Id int identity(1,1) primary key not null,--从1开始每次+1 设置主键
DemoNo varchar(50) not null,
DemoName nvarchar(50) not null,--varchar和nvarchar智能变化储存长度,nvarchar可以储存中文
TypeId int not null,--外键
Price decimal(18,2) null,--18个数字小数点后有两位
DemoCount int null
)
go
--创建外键
create table DemoType
(
TypeId int identity(1,1) primary key not null,
TypeName nvarchar(20) not null
)
--删除表
drop table DemoTable
go
--添加一列
alter table DemoTable add DemoRemark nvarchar(max) null--DemoTable中添加一列
--删除一列
alter table DemoTable drop column DemoRemark
--修改一列
alter table DemoTable alter column DemoNo nvarchar(50) null
--修改列名
exec sp_rename'DemoTable.DemoCount','Count','column'--轻易不要修改列名
--外键,在创建表中的外键时使用下面形式,后面为外键所对应的主表中的主键
TypeId int not null foreign key references DemoType(TypeId)