use master
go
if exists(select * from sysdatabases where name='bbsDB')
drop database bbsDB
go
create database bbsDB
on
(
name='bbsDB_data',
filename='D:\project\bbsDB_data.mdf',
size=10mb,
filegrowth=20%
)
log on
(
name='bbsDB_log',
filename='D:\project\bbsDB_log.ldf',
size=3mb,
maxsize=20mb,
filegrowth=10%
)
go
use bbsDB
go
if exists(select * from sysobjects where name='bbsUsers')
drop table bbsUsers
go
create table bbsUsers
(
UID int identity(1,1) not null,
Uname varchar(15) not null,
Upassword varchar(10),
Uemail varchar(20),
Ubrithday datetime not null,
Usex bit not null,
Uclass int ,
Uremark varchar(20),
UregDate datetime not null,
Ustate int null,
Upoint int null
)
go
alter table bbsUsers
add constraint PK_UID primary key(UID)
alter table bbsUsers
add constraint DF_Upassword
default (888888) for Upassword
alter table bbsUsers
add constraint DF_Usex
default (1) for Usex
alter table bbsUsers
add constraint DF_Uclass
default (1) for Uclass
alter table bbsUsers
add constraint DF_UregDate
default (getDate()) for UregDate
alter table bbsUsers
add constraint DF_Ustate
default (0) for Ustate
alter table bbsUsers
add constraint DF_Upoint
default (20) for Upoint
alter table bbsUsers
add constraint CK_Uemail
check (Uemail like '%@%')
alter table bbsUsers
add constraint CK_Upassword
check (len(Upassword)>=6)
go
insert into bbsUsers(Uname,Upassword,Uemail,Ubrithday,Uremark,Upoint)
values('可卡因','HYXS007','ss@hotmail.com','1978-07-09','我要去公安局自首',50)
insert into bbsUsers(Uname,Upassword,Uemail,Ubrithday,Uremark,Upoint)
values('可卡因','HYXS007','ss@hotmail.com','1978-07-09','我要去公安局自首',50)
select * from bbsUsers
insert into bbsUsers(Uname,Upassword,Uemail,Usex,Uclass,Ubrithday,Uremark,Ustate,Upoint)
values('心酸果冻','888888','yy@hotmail.com',0,2,'1980-02-12','走遍天涯海角',2,600)
insert into bbsUsers(Uname,Upassword,Uemail,Usex,Uclass,Ubrithday,Uremark,Ustate,Upoint)
values('冬雪儿','fangdong','bb@sohu.com',1,3,'1976-10-03','爱迷失在天堂',4,1200)
insert into bbsUsers(Uname,Upassword,Uemail,Usex,Uclass,Ubrithday,Uremark,Ustate,Upoint)
values('Super','master','dd@p.com',1,5,'1977-05-16','BBS大斑竹',1,5000)
delete from bbsUsers where UID=1
select * from bbsUsers
go
use bbsDB
if exists(select * from sysobjects where name='bbsSection')
drop table bbsSection
go
create table bbsSection
(
SID int identity(1,1) not null,
Sname varchar(32) not null,
SmasterID int not null,
Sprofile varchar(50) null,
SclickCount int null,
StopicCount int null
)
go
alter table bbsSection
add constraint PK_SID primary key(SID)
alter table bbsSection
add constraint DF_SclickCount default (0) for SclickCount
alter table bbsSection
add constraint DF_StopicCount default (0) for StopicCount
alter table bbsSection
add constraint FK_SmasterID foreign key(SmasterID) references bbsUsers(UID)
go
insert into bbsSection(Sname,SmasterID,Sprofile,SclickCount,StopicCount)
values('java技术',3,'讨论java相关,技术包括J2EE,J2ME,J2SE',500,1)
insert into bbsSection(Sname,SmasterID,Sprofile,SclickCount,StopicCount)
values('.Net技术',5,'讨论Web Service/XML,NET Remoting',800,1)
insert into bbsSection(Sname,SmasterID,Sprofile,SclickCount,StopicCount)
values('Linux/Unix社区',5,'包含系统维护与使用区,程序开发区,内核区',0,0)
go
select * from bbsSection
go
use bbsDB
if exists(select * from sysobjects where name='bbsTopic')
drop table bbsTopic
go
create table bbsTopic
(
TID int identity(1,1) not null,
TsID int not null,
TuID int not null,
TreplyCount int null,
Tface int null,
Ttopic varchar(50) not null,
Tcontents varchar(50) not null,
Ttime datetime null,
TclickCount int null,
Tstate int not null,
TlastReply datetime null
)
go
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 DF_Ttime default (getDate()) for Ttime
alter table bbsTopic
add constraint DF_TclickCount default (0) for TclickCount
alter table bbsTopic
add constraint DF_Tstate default (1) for Tstate
insert into bbsTopic(TsID,TuID,TreplyCount,Tface,Ttopic,Tcontents,Tstate,TclickCount)
values(1,3,2,1,'还是jsp中的问题','jsp文件中读取',1,200)
insert into bbsTopic(TsID,TuID,TreplyCount,Tface,Ttopic,Tcontents,Tstate,TclickCount)
values(2,2,0,2,'部署.Net中的问题','项目包括windows',1,0)
select * from bbsTopic
go
use bbsDB
if exists(select * from sysobjects where name='bbsReply')
drop table bbsReply
go
create table bbsReply
(
RID int identity(1,1) not null,
RtID int not null,
RsID int not null,
RuID int not null,
Rface int null,
Rcontents varchar(50) not null,
Rtime datetime null,
RclickCount int null
)
go
alter table bbsReply
add constraint PK_RID primary key(RID)
alter table bbsReply
add constraint FK_RtID foreign key(RtID) references bbsTopic(TID)
alter table bbsReply
add constraint FK_RsID foreign key(RsID) references bbsSection(SID)
alter table bbsReply
add constraint FK_RuID foreign key(RuID) references bbsUsers(UID)
alter table bbsReply
add constraint DF_Rtime default (getDate()) for Rtime
insert into bbsReply(RtID,RsID,RuID,Rface,Rcontents,RclickCount)
values('1','1','5','2','数据库连接池','100')
insert into bbsReply(RtID,RsID,RuID,Rface,Rcontents,RclickCount)
values('1','1','4','4','public static Data','200')
insert into bbsReply(RtID,RsID,RuID,Rface,Rcontents,RclickCount)
values('2','2','2','3','帮测试人员架AS','0')
select * from bbsReply
go
评论0