SQL ServerSQL Server 2008 添加约束

ALTER TABLE Student –主键约束
SQL Server,ADD CONSTRAINT PK_StuNo PRIMARY KEY (StudentNo)

ALTER TABLE Student –唯一约束(身份证号唯一)
ADD CONSTRAINT UQ_stuID UNIQUE (IdentityCard)

ALTER TABLE Student –默许约束(地址不详)
ADD CONSTRAINT DF_stuAddress DEFAULT (‘地址不详’) FOR Address

ALTER TABLE Student –检查约束(出生日期是自1980年八月1日之后)
ADD CONSTRAINT CK_stuBornDate CHECK(BornDate>=’1980-1-1′)

ALTER TABLE Student –添加外键约束
ADD CONSTRAINT FK_Grade
FOREIGN KEY(GradeID) REFERENCES Grade(GradeID)
go

相关文章