SQL-(4) 约束

来源:互联网 发布:coc亡灵升级数据 编辑:程序博客网 时间:2024/05/22 00:35
drop table testcreate table test (testId int primary key identity(1,1), -- 主键, 也可有复合主键testname varchar(30) unique, -- 唯一, 不允许重复,但最多只有一个空值testpass varchar(30) not null, -- 不为空,插入时不能为空testage int,deptno int foreign key references dept(deptno)-- 外键约束)-----------------------------------------------------------drop table testcreate table test (testId int,testname varchar(30) unique, testpass varchar(30) not null, testage int,primary key (testId, testname) -- 复合主键)-----------------------------------------------------------drop table testcreate table test (testId int primary key identity(1,1), testname varchar(30) unique, testpass varchar(30) not null, testage int check(testage>=1 and testage<=200),-- check 限制age的范围只能是0~200之间info ntext default '请加入自我介绍'-- default 默认值)insert into test(testname, testpass, testage) values( 'jiaozl', 'jiaozl',100)select * from test
0 0
原创粉丝点击