毕业设计BBS建表与初始化数据库
    create database bbs;
use bbs
go
--用户表
if exists(select * from sysobjects where name = 'userInfo')
	drop table userInfo
go
create table userInfo
(
	uId int identity (1,1),		--用户id【主键】
	uName nvarchar(10) not null,	--用户名【唯一约束】
	uPassWord nvarchar(20) not null,     --用户密码
	uSex bit not null,			--用户性别
	uFace nvarchar(5) not null,		--用户头像路径
	uType int not null,	--用户类型【默认为0普通会员】
	--禁言用户:-1、普通会员:0、版主:1、管理员:2
	uRegTime datetime not null	--用户注册时间【默认为当前时间】
)
go
--版块表
if exists(select * from sysobjects where name ='sectionInfo' )
	drop table sectionInfo
create table sectionInfo
(
	sId int identity(1,1),		--版块id【主键】
	sName nvarchar(20) not null,         --版块名
	sMasterId int not null,		--版主id【默认为0】	
	sTopicCount int not null,	         --帖子数量【默认为0】
	sParentId int not null		--父版块【默认为0】
)
go
--主帖表
if exists(select * from sysobjects where name ='topicInfo')
	drop table topicInfo
create table topicInfo(
	tId int identity(1,1),		--主帖id【主键】
	tSId int not null,			--所在版块id【外键】
	tUId int not null,			--发帖用户id【外键】
	tTopic nvarchar(20) not null,	--帖子标题
	tContents nvarchar(max) not null,	--主帖内容
	tReplyCount int not null,		--回复数量【默认为0】
	tClickCount int not null,		--点击数量【默认为0】
	tPublishTime datetime not null,	--发帖时间【默认为当前时间】
	tModifyTime datetime 	         --修改时间
)
go
--跟帖表
if exists(select * from sysobjects where name = 'replyInfo')
	drop table replyInfo
create table replyInfo(
	rId int identity(1,1),	--跟帖id【主键】
	rTId int not null,		--回复的主帖id【外键】
	rSId int not null,		--跟帖所在版块id【外键
	rUId int not null,		--跟帖人id【外键】
	rTopic nvarchar(20),	--跟帖主题
	rContents nvarchar(max) not null,	--跟帖内容
	rPublishTime datetime not null,--跟帖时间【默认为当前时间】
		rModifyTime datetime 	--修改时间
)
go
--论坛短信表
if exists(select * from sysobjects where name = 'messageInfo')
	drop table messageInfo
create table messageInfo(
	mId int identity(1,1),		--短信id【主键】
	mSendUnameId int not null,		--短信的发送者id【外键】
	mReceiveUnameId int not null,	--短信的接收者id【外键】
	mTopic nvarchar(20) not null,	--短信主题
	mNote nvarchar(100) not null,	--短信内容
	mPostTime datetime not null,--短信发送时间【默认为当前时间】
	mReadSign bit not null,		--【默认为false未读】
)
//表约束条件use bbs
go
--用户表约束
alter table userInfo 
	add 
	constraint PK_uId primary key (uId),
	constraint UQ_uName unique(uName),
	constraint DF_uType default(0) for uType,
	constraint  DF_uRegTime default(getdate()) for uRegTime
go
--版块表约束
alter table sectionInfo
	add 
	constraint PK_sId primary key(sId),
	constraint DF_sMasterId default(0) for sMasterId,
	constraint DF_sTopicCount default(0) for sTopicCount,
	constraint DF_sParentId default(0) for sParentId
go 
--发帖表
alter table topicInfo
	add 
	constraint PK_tId primary key(tId),
	constraint FK_tSId foreign key(tSId) references sectionInfo(sId),
	constraint FK_tUId foreign key(tUId) references userInfo(uId),
	constraint DF_tReplyCount default(0) for tReplyCount,
	constraint DF_tClickCount default(0) for tClickCount,
	constraint DF_tPublishTime default(getDate()) for tPublishTime
go
--跟帖表
alter table replyInfo
	add
	constraint PK_rId primary key(rId),
	constraint FK_rTId foreign key(rTId) references topicInfo(tId),
	constraint FK_rSId foreign key(rSId) references sectionInfo(sId),
	constraint FK_rUId foreign key(rUId) references