实体完整性约束
C表
/*1为现有表C的CN列创建UNIQUE约束*/
use testbase2
go
alter table C
add constraint unique_c unique(tn)
go
/*2删除表C中CN列的UNIQUE约束UNIQUE_C*/
use testbase2
go
alter table C drop unique_c
go
/*3为现有表TEST_TC增加新列ID_TC,并创建此属性为IDENTITY*/
/*为现有表TC增加新列ID_TC,并创建此属性为IDENTITY*/
use testbase2
go
alter table TC ADD ID_TC INT IDENTITY
go
域完整性
/*为现有数据库表Teacher创建DEFAULT和CHECK约束*/
/*删除表Teacher中PROF列和COMM列之间的CHECK约束*/
为现有表Test4创建unique约束
增加unique约束后
删除unique约束后
/*为现有表Test4创建unique约束*/
use testbase2
go
alter table Test4
add constraint UNIQUE_C unique(CNO,CN)
go
/*为现有表Test4删除unique约束*/
use testbase2
go
alter table Test4 drop UNIQUE_C
go
给现有放数据库表Teacher创建CHECK约束
use testbase2
go
alter table Teacher with CHECK
add constraint CHECK_AGE1 check(AGE>=14 AND AGE<=52)
go
给现有放数据库表S删除CHECK约束
use testbase2
go
alter table Teacher
drop constraint CHECK_AGE1
go
参照完整性
级联
use testbase2
go
alter table TC with nocheck
add constraint FK_T_TC FOREIGN KEY(TNO) REFERENCES Teacher(TNO)
on delete cascade
go