【正文】
y(RuID) references bbsUsers(UID) alter table bbsReply add constraint DF_Rcontents check(len(Rcontents) = 6) alter table bbsReply add constraint DF_Rtime default(getDate()) for Rtime 以上為創(chuàng)建bbsReply(回帖)表的內(nèi)容及各字段的約束觸發(fā)器設(shè)計(jì)1.bbsUsers表上的出發(fā)器觸發(fā)器設(shè)計(jì) :Tri_udelete 描述:當(dāng)一個(gè)用戶被管理員刪除,其發(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 描述:當(dāng)用戶的積分增加的一定值后,對應(yīng)的用戶等級會(huì)發(fā)生變化。) 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 table bbsSection add constraint DF_StopicCount default(0) for StopicCount 以上為表bbsSection(版塊表)建立及添加相應(yīng)約束 go新建bbsTopic表(主貼表) if exists(select * from sysobjects where name = 39。 or Usex=39。) alter table bbsUsers add constraint DF_Usex default(39。) drop table bbsUsecreate table bbsUsers ( UID int identity(1,1) not null, Uname varchar(50) not null,Upassword varchar(50) not null, U varchar(50), Usex char(2) not null, Uclass int, Uremark varchar(50),UregDate datetime not null, Ustate int,Upoint int, ) go 為bbsUsers表添加各種約束alter table bbsUsers add constraint PK_UID primary key(UID) alter table bbsUsers add constraint CK_Upassword check(len(Upassword) = 6) alter table bbsUsers add constraint DF_Upassword default(39。, filename = 39。,filename = 39。實(shí)施的步驟如下:使用SQL server 2000查詢分析器創(chuàng)建數(shù)據(jù)庫bbsDB,代碼如下:use master新建數(shù)據(jù)bbsDB的庫 go if exists(select * from sysdatabases where name = 39。將主貼轉(zhuǎn)換為帖子關(guān)系:(帖子編號、板塊編號、發(fā)帖人ID