求写数据库要求.sql文件
- 提问者网友:容嬷嬷拿针来
- 2021-06-06 09:41
- 五星知识达人网友:拜訪者
- 2021-06-06 11:16
Use master
Go
if exists (select * from sysdatabases where name='数据库名称')
drop database DB
Create database DB
on primary
(
name='DB_data',
filename = '路径\DB_data.mdf',
size =3mb,
filegrowth =1mb
)
log on
(
name='DB_log',
filename = '路径\DB_log.ldf',
size =3mb,
filegrowth =1mb
)
Use BBS
Go
if exists (select * from sysobjects where name='tb_admin')
drop table tb_admin
Create table tb_admin
(
adminName nvarchar(50) not null,
password nvarchar(50) null,
adminPopedom nvarchar(10) null
)
if exists (select * from sysobjects where name='tb_Host')
drop table tb_Host
Create table tb_Host
(
hostName nvarchar(50) not null,
hostId int not null,
password nvarchar(50) null,
realName nvarchar(50) null,
sex bit null,
birthday smalldatetime null,
phone nvarchar(20) null,
moble nvarchar(20) null,
content text not null,
QQId bigint null,
pic nvarchar(200) null,
email nvarchar(50) null,
address nvarchar(100) null,
contactAddress nvarchar(100) null,
selfIndex nvarchar(50) null,
hostIdRole nchar(10) null
)
alter table tb_admin add constraint PK_adminName
primary key (adminName)
alter table tb_Host add constraint PK_tb_host
primary key (hostName)
Use master
Go
if exists (select * from sysdatabases where name='BBS')
drop database BBS
Create database BBS
on primary
(
name='BBS_data',
filename = '路径\BBS_data.mdf',
size =3mb,
filegrowth =1mb
)
log on
(
name='BBS_log',
filename = '路径\BBS_log.ldf',
size =3mb,
filegrowth =1mb
)
USE BBS
go
if exists (select * from sysobjects where name='tb_user')
drop table tb_user
Create table tb_user
(
userName nvarchar(50) not null,
password nvarchar(50) null,
realName nvarchar(20) null,
userSex bit null,
birthday smalldatetime null,
moble nvarchar(20) null,
content text not null,
QQId bigint null,
pic nvarchar(200) null,
email nvarchar(50) null,
address nvarchar(100) null,
contactAddress nvarchar(100) null,
selfIndex nvarchar(50) null,
auIdRole nchar(10) null
)
alter table tb_user add constraint PK_tb_User
primary key (userName)
if exists (select * from sysobjects where name='tb_Image')
drop table tb_Image
Create table tb_Image
(
Id nvarchar(20) not null,
pic nvarchar(200) null,
)
alter table tb_Image add constraint PK_Id
primary key (Id)
if exists (select * from sysobjects where name='tb_Revert')
drop table tb_Revert
Create table tb_Revert
(
reId nvarchar(20) not null,
topic nvarchar(50) null,
id nvarchar(50) null,
content nvarchar(4000) not null,
reTime smalldateTime not null,
reUserName nvarchar(50) not null,
role nchar(10) null
)
alter table tb_Revert add constraint PK_tb_Revert
primary key (reId)
alter table tb_Revert add constraint DF_reTime
default (getDate()) for reTime
//主外键约束没写 不知道哪个主键 哪个外键