为什么执行第2次会报错?
use master
go
if exists(select * from sysdatabases where name='s2bbsDB')
drop database s2bbsDB
go
create database s2bbsDB
on
(
name='s2bbsDB_db',
filename='D:\project\s2bbsDB_db.mdf',
size=10mb,
filegrowth=20%
)
log on
(
name='s2bbsDB_log',
filename='D:\project\s2bbsDB_db.log',
size=3mb,
maxsize=20mb,
filegrowth=20mb
)
go
use s2bbsDB
go
if exists(select * from sysobjects where name='s2bbsUsers')
drop table s2bssUsers
go
create table s2bbsUsers
(
UID int Identity(1,1) NOT NULL, --自动编号
Uname varchar(15) not null, --昵称
Upassword varchar(10) not null, --密码
Uemail varchar(20), --Email
Usex bit not null, --性别
Uclass int, --等级
Uremark varchar(20), --备注
UregDate datetime not null, --注册日期
Ustate int, --状态
Upoint int --用户的积分
)
go
alter table s2bbsUsers
add constraint pk_UID primary key(UID),
constraint DF_Upassword default(888888) for Upassword,
constraint DF_Usex default(1) for Usex,
constraint DF_Uclass default(1) for Uclass,
constraint DF_UregDate default(getdate()) for Uregdate,
constraint DF_Ustate default(0) for Ustate,
constraint DF_Upoint default(20) for Upoint,
constraint CK_Ueamil check ('Ueamil' like '%@%'),
constraint CK_Upassword check (len(Upassword)>=6)
go
use s2bbsDB
go
if exists(select * from sysobjects where name='s2bbsSection')
drop table s2bbsSection
go
create table s2bbsSection
(
SID int Identity(1,1) NOT NULL, --自动编号
Sname varchar(15) not null, --昵称
SmasterID int not null, --版主的用户id
Sprofile Varchar(50), --版面简介
SclickCount int, --点击率
StopicCount int --发贴数
)
go
alter table s2bbsSection
add constraint PK_SID primary key(SID),
constraint DF_SclickCount default(0) for SclickCount,
constraint DF_StopicCount default(0) for StopicCount
go
alter table s2bbsSection
add constraint FK_s2bbsUsers_s2bbsSection foreign key(SmasterID) references s2bbsUsers(UID)
go