【正文】
k(len(Rcontents) = 6) alter table bbsReply add constraint DF_Rtime default(getDate()) for Rtime 以上為創(chuàng)建bbsReply(回帖)表的內(nèi)容及各字段的約束觸發(fā)器設(shè)計1.bbsUsers表上的出發(fā)器觸發(fā)器設(shè)計 :Tri_udelete 描述:當一個用戶被管理員刪除,其發(fā)表的主帖和跟帖也要被刪除 代碼:Use bbsDBGoCreate trigger Tri_udeleteOn bbsUsers After deleteAs Delete from bbsTopic where TuID in (select UID from deleted) Delete from bbsReply where RuID in (select UID from deleted):Tri_uupdate 描述:當用戶的積分增加的一定值后,對應(yīng)的用戶等級會發(fā)生變化。) drop table bbsTopic create table bbsTopic ( TID int identity(1,1) not null, TsID int not null, TuID int not null,TreplyCount int, Tface int, Ttopic varchar(50) not null, Tcontents varchar(50) not null,Ttime datetime, TclickCount int,Tstate int not null,TlastReply datetime ) go為bbsTopic(主貼表)表個字段添加約束 alter table bbsTopic add constraint PK_TID primary key(TID) alter table bbsTopic add constraint FK_TsID foreign key(TsID) references bbsSection (SID) alter table bbsTopic add constraint FK_TuID foreign key(TuID) references bbsUsers (UID) alter table bbsTopic add constraint DF_TreplyCount default(0) for TreplyCount alter table bbsTopic add constraint CK_Tcontents check(len(Tcontents) = 6) alter table bbsTopic add constraint DF_Ttime default(getDate()) for Ttime alter table bbsTopic add constraint DF_TclickCount default(0) for TclickCountalter table bbsTopic add constraint DF_Tstate default(1) for Tstate alter table bbsTopic add constraint CK_TlastReply check(TlastReply Ttime) 以上為bbsTopic(主貼表)表建立及各字段的約束 go 新建表bbsReply(回帖表) if exists(select * from sysobjects where name = 39。) drop table bbsSection create table bbsSection ( SID int identity(1,1) not null, Sname varchar(50) not null, SmasterID int not null, Sprofile varchar(50), SclickCount int,StopicCount int ) go 為表bbsSection(版塊表)添加約束 alter table bbsSection add constraint PK_SID primary key(SID) alter table bbsSection add constraint FK_SmasterID foreign key(SmasterID) references bbsUsers (UID) alter table bbsSection add constraint DF_SclickCount default(0) for SclickCount alter