T-SQL语句实施数据完整性

来源:互联网 发布:非英文域名 编辑:程序博客网 时间:2024/04/29 11:36

为已有列表添加空值约束

alter table ReaderType alter column rt_Name varchar(10) not null



为已有列表添加主键约束

alter table ReaderInfo alter column r_ID char(8) not null

alter table ReaderInfo add constraint pk_r_ID primary key(r_ID)



为已有列表添加外键约束

alter table BookInfo add constraint FK_bt_ID foreign key(bt_ID) references BookType (bt_ID)

alter table ReaderInfo add constraint fk_rt_ID foreign key(rt_ID) references ReaderType


为已有列表添加unique约束

alter table ReaderType add unique(rt_Name)


查找表中的约束

exec sp_helpconstraint BorrowReturn



通过约束名删除unique约束

alter table BorrowReturn drop constraint UQ__BorrowRe__2F3DA3BD29572725



为已有列表添加default定义

ALTER TABLE 表名 ADD CONSTRAINT 定义名 DEFAULT 定义值 FOR 定义对象 ;

alter table BorrowReturn add constraint df_br_OutDate default getdate() for br_OutDate



为已有列表添加check约束

ALTER TABLE 表名 WITH NOCHECK ADD CONSTRAINT 约束名 CHECK (check条件)

alter table BorrowReturn add constraint ck_br_InDate check(br_InDate > br_OutDate)


0 0
原创粉丝点击