建设网站如何赢利,wordpress如何上传,专业网站开发技术,阿里巴巴网站建设与维护训练技能点#xff1a; 学会使用sql语句创建数据库、表、约束、建立数据库关系图
使用到的软件#xff1a;SQL Server2008
代码如下#xff1a;
use master
go
if exists(select * from sysdatabases where nameBBS) --判断BBS库是否存在#xff0c;若存在则先删除drop…训练技能点 学会使用sql语句创建数据库、表、约束、建立数据库关系图
使用到的软件SQL Server2008
代码如下
use master
go
if exists(select * from sysdatabases where nameBBS) --判断BBS库是否存在若存在则先删除drop database BBScreate database BBS
on primary
(
nameBBS_data,
filenamec:\data\BBS_data.mdf,
size10,
maxsize20,
filegrowth20%
)
log on
(
nameBBS_log,
filenamec:\data\BBS_log.ldf,
size1,
maxsize10,
filegrowth10%
)
gouse BBS
go
if exists(select * from sysobjects where nameBBSUser) --判断BBSUser表是否存在若存在则先删除drop table BBSUsercreate table BBSUser --创建论坛用户表
(
UID int primary key identity not null, --用户编号设为主键
UName varchar(20) not null, --用户昵称
UPassword varchar(10) null, --密码
UEmail varchar(40) null, --电子邮件
UBirthday varchar(30) not null, --生日
USex bit not null, --性别
UClass int not null, --用户等级
UStatement varchar(50) null, --用户备注
URegDate datetime not null, --注册日期
UState int null, --用户状态
UPoint int null --用户积分
)
gouse BBS
go
if exists(select * from sysobjects where nameBBSTopic)drop table BBSTopiccreate table BBSTopic
(
TID int primary key identity not null, --标识主键列
TNumber int not null, --帖子编号
TSID int not null, --所在版块
TUID int not null, --发帖人
TReplyCount int not null, --回复数
TEmotion int null, --回复表情
TTopic varchar(40) not null, --主题
TContents varchar(40) not null, --正文
TTime datetime not null, --回复时间
TClickCount int null, --点击数
TFlag int null, --状态
TLastClickT datetime --最后回复时间
)
gouse BBS
go
if exists(select * from sysobjects where nameBBSReply)drop table BBSReplycreate table BBSReply
(
RID int primary key identity not null, --标识主键列
RNumber int not null, --帖子编号
RTID int not null, --回复的主贴
RSID int not null, --所在板块编号
RUID int not null, --发帖人编号
REmoticon int null, --发贴表情
RTopic varchar(40) not null, --主题
RContents varchar(40) not null, --正文
RTime datetime --发帖时间
)
gouse BBS
go
if exists(select * from sysobjects where nameBBSSection)drop table BBSSectioncreate table BBSSection
(
SID int primary key identity not null, --版块编号主键
SName varchar(30) not null, --版块名称
SMasterID int not null, --版主编号
SStatement varchar(30) not null, --本版格言
SClickCount int null, --点击率
STopicCount int null --帖子数量
)
go--添加约束
--1、为BBSUser表添加约束
alter table BBSUser add constraint df_UPassword default 888888 for Upassword
alter table BBSUser add constraint df_USex default 1 for Usex
alter table BBSUser add constraint df_URegDate default getdate() for URegDate
alter table BBSUser add constraint df_UState default 0 for UState
alter table BBSUser add constraint df_UClass default 1 for UClass
alter table BBSUser add constraint df_UPoint default 10 for UPoint
alter table BBSUser add constraint ck_UPassword check(len(UPassword)6)--2、为BBSTopic表添加约束
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_TLastClickT default getdate() for TLastClickT
alter table BBSTopic add constraint fk_TSID foreign key(TSID) references BBSSection(SID)
alter table BBSTopic add constraint fk_TUID foreign key(TUID) references BBSUser(UID)--3、为BBSReply表添加约束
alter table BBSReply add constraint df_RTime default getdate() for RTime
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 BBSUser(UID)--4、为BBSSection表添加约束
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 BBSUser(UId)运行上述代码并刷新后便可见创建的数据库、表以及约束 如下 其数据库关系图如下图
在建立数据库关系图时开始就遇见了一些问题不知道咋建立关系图然后查了查资料就解决了如果有类似情况的小伙伴请进入传送门一起来解决这个问题吧
点击此处打开传送门SQL Server如何建立数据库关系图别急一串代码让你轻松永久解决此类问题