有四个表结构如下:-------------------------------------------------------
go
create table BBSUsers --创建用户信息表
(uid int not null primary key identity(1,1), --用户ID
uname varchar(32) not null, --用户名
upassword varchar(16) not null default('888888') check(len(upassword)>=6),--密码
uemail varchar(32) default('[email protected]') check(uemail like '%@%'),--电子邮件
ubirthdar datetime, --生日
usex bit not null default(1), --性别
uclass int default(1), --用户等级
ustatement varchar(255), --备注信息
uregdate datetime not null, --注册日期
ustate int default(1), --状态
upoint int default(20) --用户积分
)go
create table BBSSection --创建版块表
(SID int not null primary key identity(1,1), --版块ID
SName varchar(32) not null, --版块名称
SMasterID int not null --用户ID,外健
foreign key(SMasterID) references BBSUsers(UID),
SStatement varchar(255), --本版格言
SClickCount int, --点击率
STopicCount int --发贴数
)
go
insert bbssection --版块表插入数据
select '物品交易',3,'买卖有风险、入市请慎重',0,0 union
select '综合讨论',2,'有话就说',0,0go
create table BBSTopic --创建主贴表
(TID int not null primary key identity(1,1), --主贴ID
TNumber varchar(32) not null, --贴子编号
TSID int not null --版块ID,外键
foreign key(TSID) references BBSSection(SID),
TUID int not null --用户ID,外键
foreign key(TUID) references BBSUsers(UID),
TReplyCount int, --回复数量
TEmotion int, --发贴表情
TTopic varchar(255) not null check(ttopic not like ''''), --标题信息
TContents nText not null, --贴子正文
TTime datetime, --发贴时间
TClickCount int, --点击数
TFlag int not null default(1), --状态
TLastClickT datetime --最后回复时间
)
go
alter table BBSTopic with check add constraint[resTime] check(TLastClickT>TTime and TLastClickT<=getdate())go
create table BBSReply --创建跟贴表
(RID int not null primary key identity(1,1), --跟贴ID
RNumber varchar(32) not null, --贴子编号
RTID int not null --主贴ID,外健
foreign key(RTID) references BBSTopic(TID),
RSID int not null --版块ID,外健
foreign key(RSID) references BBSSection(SID),
RUID int not null --用户ID,外健
foreign key(RUID) references BBSUsers(UID),
REmotion int, --回贴表情
RTopic varchar(255) not null, --标题信息
RContents nText not null, --跟贴正文
RTime datetime, --回贴时间
RClickCount int) --点击数————————————————————————————————————————---------------
查询要求 :
1.版块名称:综合讨论
2.在综合讨论版块中,每个主贴的今日回复数量*10+点击数最大的前五名主贴