表格数据
-
创建表格
create table 表面 ( 字段名 类型 primary key identity(1,1), 字段名字 类型 default('默认值'), 字段名 类型 Check(字段名>0 or 字段名<100) ) go
-
primary key:主键约束,非空且为一.
-
not null:非空约束,不能插入空值.
-
check:检查约束.
-
default :默认约束,可以设置默认值
-
unique:唯一约束,可以为空,值不能重复
-
getdate():方法,可以获取当前系统的时间
删除表里的数据(删除表的结构)
-
删除表里的数据
delete 表名
2.删除表的结构
drop table 表名
修改字段的数据类型的长度
alter table 表名 alter column 要修改的字段名 类型(长度)
添加字段
alter table 表名 add 要添加的字段名 类型(长度)
删除字段
alter table 表名 drop column 要删除的字段名字
添加约束
alter table 表名 add constraint 要删除的约束名字
外键
foreign key references 另一个表名(要链接的字段)
-
foreign key:外键约束
-
references:引用
-