简单BBS数据库的设计

基本信息表     

                                  BBSUsers  表
---------------------------------------------------------------------------------------------       属性名称        类型          长度        备注
       UID              varchar       16         用户账号------>(主键)
      UName          varchar          50          用户名
      UpassWord     varchar           16          账户密码
      UEmail           varchar        50         邮箱
      UBirthday       smalldate                 生日
      USex             nvarchar        4          性别------> in(男,女,保密)
      UClass           int                           账户级别 ------>(0级)    
      UStatement   nvarchar          100        个性签名
                                     BBSSession表
---------------------------------------------------------------------------------------------    SID                varchar      16          版块ID--> 主键
    SName           nvarchar        50          版块名称
    Smaster          varchar        16          用户ID
    Sclickcount      long           20          点击率 ------>(默认0)
    STopiccunt      long            20         主题点击率------>(默认0)
    SStatement     nvarchar         50         版块简介
---------------------------------------------------------------------------------------------                                      BBStopic表
---------------------------------------------------------------------------------------------   TID                 varchar         16        主题编号------>主键
   TNumber         int                           自增变量
   TSID               varchar          16        版块ID
   TUID               varchar          16         用户ID
   TReplycount     int                            回帖数------>默认0
   TEmotion         nvarchar           16        心情------>空
   TTopic            n varchar         50        主题题目
   TContent         text                         帖子内容
   TTime             datetime                   发帖时间 ------>getdate()
   TClickcount      long               20        点击率 ------>默认为0
   TFlag              nvarchar         16        标签
   TLastclick        datetime                   最后浏览时间  ------>getdate()
---------------------------------------------------------------------------------------------                                   BBSReplay表
---------------------------------------------------------------------------------------------   RID               varchar          16       楼主ID------>
  RNumber        int                          自增变量
  RTID             varchar            16       帖子ID
  RSID             varchar            16      版块ID
  RUID             varchar            16      用户ID
  REmotion      n varchar             16      心情------>空
  RTopic           nvarchar           50     帖子主题
  RContents      text                        回复内容
  RTime           datetime                 回复时间------>getdate()
  RClickcount    int                          回复点击数  ------>默认0
---------------------------------------------------------------------------------------------

 

Sql 语句

--------------------------创建数据库---------------------------------use master
go
if exists(select * from sysdatabases where name='BBSDB')
Drop database BBSDB
create database BBSDB
on primary
(
 name='BBSDB_data',
 FileName='E:/SQLData/BBSDB_data.mdf',
 Size=5mb,
 Maxsize=1GB,
 Filegrowth=10%
)
log on
(
 name='BBSDB_log',
 FileName='E:/SQLData/BBSDB_log.ldf',
 Size=5mb,
 Maxsize=500mb,
 Filegrowth=20%
)
go
--------------------------创建数据BBSUsers表-------------------------/*----------------------------------------------------------------       属性名称        类型          长度        备注
       UID           varchar         16         用户账号------>(主键)
      UName          varchar         50         用户名
      UpassWord      varchar         16         账户密码
      UEmail         varchar         50         邮箱
      UBirthday      smalldate                  生日
      USex           varchar         4          性别------> in(男,女,保密)
      UClass         int                        账户级别 ------>(0级)    
      UStatement     nvarchar        100        个性签名
-----------------------------------------------------------------*/
use BBSDB
if exists(select * from sysobjects where name='BBSUsers')
drop table BBSUsers
create table BBSUsers
(
UID varchar(16) not null,
UName varchar(50) not null,
Upassword varchar(16)not null,
UEmail varchar (50) not null,
UBirthday smalldatetime,
USex varchar (4) not null,
UClass int not null,
UStatement nvarchar
)
go
--------------------------创建数据BBSSession表------------------------/*----------------------------------------------------------------    SID                varchar        16          版块ID--> 主键
    SName              varchar        50          版块名称
    Smaster            varchar        16          用户ID
    Sclickcount        long           20          点击率 ------>(默认0)
    STopiccunt         long           20          主题点击率------>(默认0)
    SStatement         nvarchar       50          版块简介
----------------------------------------------------------------- */
if exists(select * from sysobjects where name='BBSSession')
drop table BBSSession
create table BBSSession
(
SID varchar(16) not null,
SName varchar(50) not null,
Smaster varchar(16)not null,
Sclickcount int not null,
STopiccunt int not null,
SStatement nvarchar (50) not null
)
go
--------------------------创建数据BBStopic表-----------------------------------
/*----------------------------------------------------------------    TID                 varchar         16        主题编号------>主键
   TNumber             int                       自增变量
   TSID                varchar         16        版块ID
   TUID                varchar         16        用户ID
   TReplycount         int                       回帖数------>默认0
   TEmotion            nvarchar         16       心情------>空
   TTopic              nvarchar         50       主题题目
   TContent            text                      帖子内容
   TTime               datetime                  发帖时间 ------>getdate()
   TClickcount         int                       点击率 ------>默认为0
   TFlag               varchar         16        标签
   TLastclickt         datetime                  最后浏览时间  ------>getdate()
-----------------------------------------------------------------*/
if exists(select * from sysobjects where name='BBStopic')
drop table BBStopic
create table BBStopic
(
TID varchar(16) not null,
TNumber int identity(1,1) not null,
TSID varchar(16)not null,
TUID varchar(16) not null,
TReplycount int not null,
TEmotion nvarchar (16) not null,
TTopic nvarchar(50) not null,
TContent text not null,
TTime datetime  not null,
TClickcount int not null,
TFlag nvarchar(16)not null,
TLastclickt datetime not null,

)
go
--------------------------创建数据BBSReplay表------------------------/*-----------------------------------------------------------------  RID            varchar          16      楼主ID
  RNumber        int                      自增变量
  RTID           varchar          16      帖子ID
  RSID           varchar          16      版块ID
  RUID           varchar          16      用户ID
  REmotion       nvarchar         16      心情------>空
  RTopic         nvarchar         50      帖子主题
  RContents      text                     回复内容
  RTime          datetime                 回复时间------>getdate()
  RClickcount    int                      回复点击数  ------>默认0
-----------------------------------------------------------------*/
if exists(select * from sysobjects where name='BBSReplay')
drop table BBSReplay
create table BBSReplay
(
RID varchar(16) not null,
RNumber int identity(1,1) not null,
RTID varchar(16)not null,
RSID varchar(16) not null,
RUID varchar(16) not null,
TEmotion nvarchar (16),
RTopic nvarchar(50) not null,
RContents text not null,
RTime datetime not null,
RClickcount int not null,
)
go
--------------------------为BBSUsers表创建约束-----------------------/*-----------------------------------------------------------------       属性名称        类型          长度        备注
      UID           varchar          16         用户账号------>(主键)
      UName          varchar         50         用户名
      UpassWord      varchar         16         账户密码
      UEmail         varchar         50         邮箱
      UBirthday      smalldate                  生日
      USex           varchar         4          性别------> in(男,女,保密)
      UClass         int                        账户级别 ------>(0级)    
      UStatement     nvarchar        100        个性签名
-----------------------------------------------------------------*/
------------------创建主键约束-------->PK_BBSUSERS_UID
if exists(select * from sysobjects where name='PK_BBSUSERS_UID')
alter table BBSUsers drop constraint PK_BBSUSERS_UID
alter table BBSUsers add constraint PK_BBSUSERS_UID
primary key(UID)
go
------------------创建检查约束-------->CK_BBSUSERS_USEX
if exists(select * from sysobjects where name='CK_BBSUSERS_USEX')
alter table BBSUsers drop constraint CK_BBSUSERS_USEX
alter table BBSUsers add constraint CK_BBSUSERS_USEX
check(USex in('男','女','保密'))
go
------------------创建默认约束-------->DF_BBSUSERS_USEX
if exists(select * from sysobjects where name='DF_BBSUSERS_USEX')
alter table BBSUsers drop constraint DF_BBSUSERS_USEX
alter table BBSUsers add constraint DF_BBSUSERS_USEX
default('保密') for USex
go
------------------创建默认约束-------->DF_BBSUSERS_UCLASS
if exists(select * from sysobjects where name='DF_BBSUSERS_UCLASS')
alter table BBSUsers drop constraint DF_BBSUSERS_UCLASS
alter table BBSUsers add constraint DF_BBSUSERS_UCLASS
default('0级') for UClass
go

---------------------------------------------------------------------------------------------为BBSSession表创建约束----------------------/*-----------------------------------------------------------------    SID                varchar        16          版块ID--> 主键
    SName              varchar        50          版块名称
    Smaster            varchar        16          用户ID
    Sclickcount        long           20          点击率 ------>(默认0)
    STopiccunt         long           20          主题点击率------>(默认0)
    SStatement         nvarchar       50          版块简介
----------------------------------------------------------------------------- */
------------------创建主键约束-------->PK_BBSSESSION_SID
if exists(select * from sysobjects where name='PK_BBSSESSION_SID')
alter table BBSSession drop constraint PK_BBSSESSION_SID
alter table BBSSession add constraint PK_BBSSESSION_SID
primary key(SID)
go
------------------创建默认约束-------->DF_BBSSESSION_SCLICKCONUT
if exists(select * from sysobjects where name='DF_BBSSESSION_SCLICKCONUT')
alter table BBSSession drop constraint DF_BBSSESSION_SCLICKCONUT
alter table BBSSession add constraint DF_BBSSESSION_SCLICKCONUT
default(0) for Sclickcount
go
------------------创建默认约束-------->DF_BBSSESSION_STOPICCONUT
if exists(select * from sysobjects where name='DF_BBSSESSION_STOPICCONUT')
alter table BBSSession drop constraint DF_BBSSESSION_STOPICCONUT
alter table BBSSession add constraint DF_BBSSESSION_STOPICCONUT
default(0) for STopiccunt
go
------------------创建外键约束-------->FK_BBSSESSION_SMASTER
if exists(select * from sysobjects where name='FK_BBSSESSION_SMASTER')
alter table BBSSession drop constraint FK_BBSSESSION_SMASTER
alter table BBSSession add constraint FK_BBSSESSION_SMASTER
foreign key(Smaster) references BBSUsers (UID)
go

--------------------------为BBStopic表创建约束------------------------/*-----------------------------------------------------------------   TID                 varchar         16        主题编号------>主键
   TNumber             int                       自增变量
   TSID                varchar         16        版块ID
   TUID                varchar         16        用户ID
   TReplycount         int                       回帖数------>默认0
   TEmotion            nvarchar         16       心情------>空
   TTopic              nvarchar         50       主题题目
   TContent            text                      帖子内容
   TTime               datetime                  发帖时间 ------>getdate()
   TClickcount         int                       点击率 ------>默认为0
   TFlag               varchar         16        标签
   TLastclickt          datetime                  最后浏览时间  ------>getdate()
-----------------------------------------------------------------*/
------------------创建主键约束-------->PK_BBSTOPIC_TID
if exists(select * from sysobjects where name='PK_BBSTOPIC_TID')
alter table BBStopic drop constraint PK_BBSTOPIC_TID
alter table BBStopic add constraint PK_BBSTOPIC_TID
primary key(TID)
go
------------------创建默认约束-------->PK_BBSTOPIC_TREPLYCOUNT
if exists(select * from sysobjects where name='PK_BBSTOPIC_TREPLYCOUNT')
alter table BBStopic drop constraint PK_BBSTOPIC_TREPLYCOUNT
alter table BBStopic add constraint PK_BBSTOPIC_TREPLYCOUNT
default(0) for TReplycount
go
------------------创建默认约束-------->PK_BBSTOPIC_TCLICKCOUNT
if exists(select * from sysobjects where name='PK_BBSTOPIC_TCLICKCOUNT')
alter table BBStopic drop constraint PK_BBSTOPIC_TCLICKCOUNT
alter table BBStopic add constraint PK_BBSTOPIC_TCLICKCOUNT
default(0) for TClickcount
go
------------------创建默认约束-------->DF_BBSTOPIC_TTIME
if exists(select * from sysobjects where name='DF_BBSTOPIC_TTIME')
alter table BBStopic drop constraint DF_BBSTOPIC_TTIME
alter table BBStopic add constraint DF_BBSTOPIC_TTIME
default(getdate()) for TTime
go
------------------创建默认约束-------->DF_BBSTOPIC_TLASTCLICKT
if exists(select * from sysobjects where name='DF_BBSTOPIC_TLASTCLICKT')
alter table BBStopic drop constraint DF_BBSTOPIC_TLASTCLICKT
alter table BBStopic add constraint DF_BBSTOPIC_TLASTCLICKT
default(getdate()) for TLastclickt
go
------------------创建外键约束-------->FK_BBSTOPIC_TUID
if exists(select * from sysobjects where name='FK_BBSTOPIC_TUID')
alter table BBStopic drop constraint FK_BBSTOPIC_TUID
alter table BBStopic add constraint FK_BBSTOPIC_TUID
foreign key(TUID) references BBSUsers (UID)
go
------------------创建外键约束-------->FK_BBSTOPIC_TSID
if exists(select * from sysobjects where name='FK_BBSTOPIC_TSID')
alter table BBStopic drop constraint FK_BBSTOPIC_TSID
alter table BBStopic add constraint FK_BBSTOPIC_TSID
foreign key(TSID) references BBSSession (SID)
go
--------------------------为BBSReplay表创建约束

/*-----------------------------------------------------------------   RID            varchar          16      楼主ID
  RNumber        int                      自增变量
  RTID           varchar          16      帖子ID
  RSID           varchar          16      版块ID
  RUID           varchar          16      用户ID
  REmotion       nvarchar         16      心情------>空
  RTopic         nvarchar         50      帖子主题
  RContents      text                     回复内容
  RTime          datetime                 回复时间------>getdate()
  RClickcount    int                      回复点击数  ------>默认0
-----------------------------------------------------------------*/
------------------创建主键约束-------->PK_BBSREPLAY_RID
if exists(select * from sysobjects where name='PK_BBSREPLAY_RID')
alter table BBSReplay drop constraint PK_BBSREPLAY_RID
alter table BBSReplay add constraint PK_BBSREPLAY_RID
primary key(RID)
go
------------------创建默认约束-------->DF_BBSREPLAY_RTIME
if exists(select * from sysobjects where name='DF_BBSREPLAY_RTIME')
alter table BBSReplay drop constraint DF_BBSREPLAY_RTIME
alter table BBSReplay add constraint DF_BBSREPLAY_RTIME
default(getdate()) for RTime
go
------------------创建默认约束-------->PK_BBSREPLAY_RCLICKCOUNT
if exists(select * from sysobjects where name='PK_BBSREPLAY_RCLICKCOUNT')
alter table BBSReplay drop constraint PK_BBSREPLAY_RCLICKCOUNT
alter table BBSReplay add constraint PK_BBSREPLAY_RCLICKCOUNT
default(0) for RClickcount
go
------------------创建外键约束-------->FK_BBSREPLAY_RTID
if exists(select * from sysobjects where name='FK_BBSREPLAY_RTID')
alter table BBSReplay drop constraint FK_BBSREPLAY_RTID
alter table BBSReplay add constraint FK_BBSREPLAY_RTID
foreign key(RTID) references BBSTopic (TID)
go
------------------创建外键约束-------->FK_BBSREPLAY_RSID
if exists(select * from sysobjects where name='FK_BBSREPLAY_RSID')
alter table BBSReplay drop constraint FK_BBSREPLAY_RSID
alter table BBSReplay add constraint FK_BBSREPLAY_RSID
foreign key(RSID) references BBSSession (SID)
go
------------------创建外键约束-------->FK_BBSREPLAY_RUID
if exists(select * from sysobjects where name='FK_BBSREPLAY_RUID')
alter table BBSReplay drop constraint FK_BBSREPLAY_RUID
alter table BBSReplay add constraint FK_BBSREPLAY_RUID
foreign key(RUID) references BBSUsers(UID)
go

  • 2
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BBS论坛系统数据库设计 0.后台用户管理(TAB_USER) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "自增ID "id "int " "Y "N " " "2 "用户帐号 "usercode "varchar "20 " "N "登录用 " "3 "姓名 "username "varchar "20 " "N " " "3 "密 码 "pwd "varchar "11 " "N "用MD5加" " " " " " " " "密算法 " "4 "性别 "ssex "varchar "10 " " " " "5 "角色 "role "int " " " " " "6 "Email地址"email "varchar "30 " " " " " " 1.前台用户注册表(TAB_USER_REGISTER) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "自增ID "id "int " "Y "N " " "2 "用户帐号 "usercode "varchar "50 " "N "登录用 " "3 "姓名 "username "varchar "50 " "N " " "3 "密 码 "userpsw "varchar "11 " "N "用MD5加" " " " " " " " "密算法 " "4 "昵称 "nickname "varchar "50 " " " " "5 "头像 "image " " " " " " "6 "Email地址"email "varchar "80 " " " " "7 "验证码 "checkno "bigint "10 " " " " " " 用户发帖表(TAB_USER_SENDCARD) "序号 "字段名称 "字段英文名 "数据类型 "长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "发帖ID "sendcardid "int " "Y "N "自增 " "2 "发帖区ID "sendzoneid "int " " " "参照发 " " " " " " " " "帖区 " "3 "用户帐号 "usercode "varchar "30 " " " " "4 "主题 "title "varchar "200 " "N " " "5 "发帖内容 "cardcontent "varchar "1000" " " " "6 "日期 "date "date " " " " " "7 "验证码 "checkno "bigint " " " " " "发帖ID的值来判断级别。 " 用户跟帖表(TAB_USER_FOLLOWCARD) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "跟帖ID "followcardid "int " "Y "N "自增 " "2 "讨论区ID "discussid "int " " " "参照推 " " " " " " " " "荐讨论 " " " " " " " " "区ID和 " " " " " " " " "技术讨 " " " " " " " " "论区ID " "3 "用户帐号 "usercode "varchar "30 " " " " "4 "发帖ID "sendcardid "int " " " "参照发 " " " " " " " " "帖表sen" " " " " " " " "dcardID" " " " " " " " "(1:n " " " " " " " " ") " "5 "跟帖内容 "followcardconte"varchar "1000" " " " " " "nt " " " " " " "6 "日期 "date "date " " " " " "7 "验证码 "checkno " " " " " " " " 公告管理表(TAB_NOTICEMANAGE ) "序号 "字段名称 "字段英文名 "数据类型"长度"PK(Y/N) "NULL(Y/N)"备注 " "1 "公告ID "noticeid "int " "Y "N "自增 " "2 "公告时间 "noticetime "date " " " " " "3 "公告内容 "content "varchar "200 " "N " " "4 "作者 "author "varchar "50 " " " " "5 "备注 "remark "varchar "100 " " " " " " 推荐讨论区表(TAB_RECOMMANDMANAGE) "序号 "字段名称 "字段英文名 "数据 "长度"PK(
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值