约束是SQL Sever自动强制数据库完整的方式,约束定义了列中允许的取值。在SQL Sever中提供五种类型的完整性约束。 1、NULL/NOT NULL 约束;2、UNIQUE约束(唯一约束);3、PRIMARY KEY 约束(主键约束);4、FOREIGN KEY 约束(外键约束)5、CHECK 约束 例如:1、create table s(Sno char(6) not null, Sname char(10)) 2、create table s(Sno char(6) , Sname char(10) unique) 3、create table s(Sno char(6) primary key, Sname char(10)) 4、create table SC(Sno char(6) not null foreign key references S(Sno)) 5、create table SC(Sno char(6), Cno char(6), Score double check(Score>=0 and Score<=100)) ---------- 数据库完整性,比如,表中的属性,有些是必须有唯一性的,日常生活中的员工表,不可能两个一模一样的员工,所以要设置 主键让其具备唯一性。 (责任编辑:admin) |