我是一个软件编程爱好者,最近在学习SQL server的编程,身旁没什么高人指导,刚才在编写创建数据库和表时运行环境出现了报错,弄了很久也没明白哪错了,还请各位经验丰富的老鸟帮我这个菜鸟新手看看,感激不尽~
  代码如下:
/*创建数据库*/use master
if exists (select * from sysdatabases where name = 'bbsDB')
drop database bbsDBgoexec xp_cmdshell 'mkdir D:\zhao1280'--调用DOS命令创建文件夹create database bbsDB
on primary
(
name='bbsDB_data',
filename='D:\zhao1280\bbsDB_data.mdf',
size=5mb,
maxsize=100mb,
filegrowth=2mb
)
log on
(
name='bbsDB_log',
filename='D:\zhao1280\bbsDB_log.ldf',
size=2mb,
filegrowth=2mb
)
go/*创建表bbsUSer*/use bbsDB
if exists(select * from sysobjects where name = 'bbsUser')
drop table bbsUser
go
create table bbsuser
(
UID int not null identity(1,1),--用户编号,表示列
Uname varchar(15) not null, --用户名
Upassword varchar(50) not null, ---密码,必须大于六位
UEmail varchar(20), --允许为空,必须包含“@”
Usex bit not null, --性别,默认为男(1)
Uclass int,  --默认1
Ure varchar(20),
UregDate datetime not null,--默认当天日期
Ustate int,--默认为0
Upoint int, --默认为20
)
go
/*添加约束*/alter table bbsUser
add constraint PK_UID primary key(UID)
alter table bbsUser
add constraint DF_Upassword default(888888) for Upassword
alter table bbsUser
add constraint CK_UEmail check(UEmail like '%@%')
alter table bbsUser
add constraint DF_Usex default(1) for Usex
alter table bbsUser
add constraint DF_Ulaass default(1) for Uclass
alter table bbsUser
add constraint DF_UregData default(getdate()) for UregData
alter table bbsUser
add constraint DF_Ustate default(0) for Ustate
alter table bbsUser
add constraint DF_Upoint default(20) for Upoint 
go
use bbsDB/*创建表bbsSection*/
if exists(select * from sysobjects where name ='bbsSection')--一个空格导致的错误
drop table bbsSection
gocreate table bbsSection
(
SID int not null identity(1,1),--标识列
Sname varchar(32) not null,--板块名称
SmasterID int not null,--版主ID,foreign引用bbsuser中的UID
Sprofile varchar(20),--版面简介
SclickCount int ,--点击率,默认为0
StopicCount int ,--发帖数默认为0
)
goalter table bbsSection
add constraint PK_SID primary key(SID)
alter table bbsSection
add constraint FK_SmasterID foreign key(SmasterID) references bbsUSer(UID)
alter table bbsSection
add constraint DF_SclickCount default(0) for SclickCount
alter table bbsSection 
add constraint DF_StopicCount default(01) for StopicCount /*创建表bbsTopic*/
if exists(select * from sysobjects where name = 'bbsTopic')
drop table bbsTopicgocreate table bbsTopic
(
TID int identity(1,1),--标识列
TsID int,--板块编号,引用bbsSection表的SID
TuID int,--发帖人ID,引用bbsuser表的UID
treplyCount int,--回复数量,默认为0
Tface int ,--回帖表情
Ttopic varchar(20) not null,--标题
Tcontents varchar(30) not null,--必须大于六个字符
Ttime datetime ,--发帖时间,默认为当天时间
TclickCount int ,-- 点击数,默认为0
Tstate int not null,--默认为1
TlastReply datetime ,--最后回复时间
)
goalter 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 bbsUser(UID)alter table bbstopic
add constraint DF_treplyCOunt default(0) for treplyCountalter table bbstopic
add constraint CK_Tcontents check(len(Tcontents)>=6)alter table bbstopic
add constraint DF_Ttime default(getdate()) for Ttimealter table bbstopic
add constraint DF_TclickCount default(0) for TclickCountalter table bbstopic
add constraint DF_Tstate default(1) for Tstatego
/*创建数据库*/use master
if exists (select * from sysdatabases where name = 'bbsDB')
drop database bbsDBgoexec xp_cmdshell 'mkdir D:\zhao1280'--调用DOS命令创建文件夹create database bbsDB
on primary
(
name='bbsDB_data',
filename='D:\zhao1280\bbsDB_data.mdf',
size=5mb,
maxsize=100mb,
filegrowth=2mb
)
log on
(
name='bbsDB_log',
filename='D:\zhao1280\bbsDB_log.ldf',
size=2mb,
filegrowth=2mb
)
go/*创建表bbsUSer*/use bbsDB
if exists(select * from sysobjects where name = 'bbsUser')
drop table bbsUser
go
create table bbsuser
(
UID int not null identity(1,1),--用户编号,表示列
Uname varchar(15) not null, --用户名
Upassword varchar(50) not null, ---密码,必须大于六位
UEmail varchar(20), --允许为空,必须包含“@”
Usex bit not null, --性别,默认为男(1)
Uclass int,  --默认1
Ure varchar(20),
UregDate datetime not null,--默认当天日期
Ustate int,--默认为0
Upoint int, --默认为20
)
go
/*添加约束*/alter table bbsUser
add constraint PK_UID primary key(UID)
alter table bbsUser
add constraint DF_Upassword default(888888) for Upassword
alter table bbsUser
add constraint CK_UEmail check(UEmail like '%@%')
alter table bbsUser
add constraint DF_Usex default(1) for Usex
alter table bbsUser
add constraint DF_Uclass default(1) for Uclass
alter table bbsUser
add constraint DF_UregData default(getdate()) for UregData
alter table bbsUser
add constraint DF_Ustate default(0) for Ustate
alter table bbsUser
add constraint DF_Upoint default(20) for Upoint 
go
use bbsDB/*创建表bbsSection*/
if exists(select * from sysobjects where name ='bbsSection')--一个空格导致的错误
drop table bbsSection
gocreate table bbsSection
(
SID int not null identity(1,1),--标识列
Sname varchar(32) not null,--板块名称
SmasterID int not null,--版主ID,foreign引用bbsuser中的UID
Sprofile varchar(20),--版面简介
SclickCount int ,--点击率,默认为0
StopicCount int ,--发帖数默认为0
)
goalter table bbsSection
add constraint PK_SID primary key(SID)
alter table bbsSection
add constraint FK_SmasterID foreign key(SmasterID) references bbsUSer(UID)
alter table bbsSection
add constraint DF_SclickCount default(0) for SclickCount
alter table bbsSection 
add constraint DF_StopicCount default(01) for StopicCount /*创建表bbsTopic*/
if exists(select * from sysobjects where name = 'bbsTopic')
drop table bbsTopicgocreate table bbsTopic
(
TID int identity(1,1),--标识列
TsID int,--板块编号,引用bbsSection表的SID
TuID int,--发帖人ID,引用bbsuser表的UID
treplyCount int,--回复数量,默认为0
Tface int ,--回帖表情
Ttopic varchar(20) not null,--标题
Tcontents varchar(30) not null,--必须大于六个字符
Ttime datetime ,--发帖时间,默认为当天时间
TclickCount int ,-- 点击数,默认为0
Tstate int not null,--默认为1
TlastReply datetime ,--最后回复时间
)
goalter 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)alter table bbstopic
add constraint DF_treplyCOunt default(0) for treplyCountalter table bbstopic
add constraint CK_Tcontents check(len(Tcontents)>=6)alter table bbstopic
add constraint DF_Ttime default(getdate()) for Ttimealter table bbstopic
add constraint DF_TclickCount default(0) for TclickCountalter table bbstopic
add constraint DF_Tstate default(1) for Tstatealter table bbstopic
add constraint PK_TID primary key(TID)
go
if exists(select * from sysobjects where name = 'bbsReply')
 drop table bbsReplycreate table bbsReply
(
RID int not null,--标识列
RtID int not null,--引用bbsTopic,TID
RsID int not  null,--引用bbsSection,sid
RuID int not null,--引用bbsuser,UID
Rface int ,
Rcontents varchar(30) not null ,--字符大于六
Rtime datetime ,--默认当天时间
RclickCount int ,
)goalter 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)
alter table bbsReply 
add constraint CK_Rcontents check(len(Rcontents)>6)
alter table bbsReply
add constraint DF_Rtime default(getdate()) for Rtimego
编译器出现了下面的错误:
(2 行受影响)
消息 1752,级别 16,状态 0,第 15 行
表 'bbsUser' 中的列 'UregData' 对于创建默认约束无效。
消息 1750,级别 16,状态 0,第 15 行
无法创建约束。请参阅前面的错误消息。(2 行受影响)
消息 1752,级别 16,状态 0,第 15 行
表 'bbsUser' 中的列 'UregData' 对于创建默认约束无效。
消息 1750,级别 16,状态 0,第 15 行
无法创建约束。请参阅前面的错误消息。