創(chuàng)建數(shù)據(jù)庫表
use master --切換到master數(shù)據(jù)庫
go
--檢測是否存在同名的數(shù)據(jù)庫
if exists(select 1 from sysdatabases where name = 'tour')
begin
drop database tour
end
go
create database tour
on --數(shù)據(jù)文件
(
name = 'tour_mdf', --數(shù)據(jù)文件邏輯名
filename = 'D:\tour.mdf',--數(shù)據(jù)文件存放路徑
size = 1MB,--初始大小
maxsize = 10MB,--最大大小
filegrowth = 1MB--增長速度
)
log on --日志文件
(
name = 'tour_ldf', --日志文件邏輯名
filename = 'D:\tour.ldf',--日志文件存放路徑
size = 1MB,--初始大小
maxsize = 10MB,--最大大小
filegrowth = 1MB--增長速度
)
go
use tour
go
創(chuàng)建數(shù)據(jù)庫表
if exists(select * from sysobjects where name='stuInfo') drop table stuInfo
create table stuInfo /*-創(chuàng)建學員信息表-*/
(
stuNo varchar(6) not null unique, --學號,非空(必填)
stuName varchar(20) not null , --姓名,非空(必填)
stuAge int not null, --年齡,INT類型默認為4個字節(jié)
stuID NUMERIC(18,0), --身份證號
stuSeat int IDENTITY (1,1), --座位號,自動編號
stuAddress text --住址,允許為空,即可選輸入
)
go
if exists(select * from sysobjects where name='stuMarks') drop table stuMarks
create table stuMarks
(
ExamNo varchar(6) not null foreign key references stuInfo(stuNo) , --考號
stuNo varchar(6) not null, --學號
writtenExam int not null, --筆試成績
LabExam int not null --機試成績
)
go
if exists(select * from sysobjects where name='users') drop table users
create table users
(
userID int not null primary key identity(1,1),
userName varchar(255) not null unique,
userPWD varchar(255) not null,
userAge int,
userBirthDay datetime,
userEmail varchar(255)
)
go
use master --切換到master數(shù)據(jù)庫
go
--檢測是否存在同名的數(shù)據(jù)庫
if exists(select 1 from sysdatabases where name = 'tour')
begin
drop database tour
end
go
create database tour
on --數(shù)據(jù)文件
(
name = 'tour_mdf', --數(shù)據(jù)文件邏輯名
filename = 'D:\tour.mdf',--數(shù)據(jù)文件存放路徑
size = 1MB,--初始大小
maxsize = 10MB,--最大大小
filegrowth = 1MB--增長速度
)
log on --日志文件
(
name = 'tour_ldf', --日志文件邏輯名
filename = 'D:\tour.ldf',--日志文件存放路徑
size = 1MB,--初始大小
maxsize = 10MB,--最大大小
filegrowth = 1MB--增長速度
)
go
use tour
go
創(chuàng)建數(shù)據(jù)庫表
if exists(select * from sysobjects where name='stuInfo') drop table stuInfo
create table stuInfo /*-創(chuàng)建學員信息表-*/
(
stuNo varchar(6) not null unique, --學號,非空(必填)
stuName varchar(20) not null , --姓名,非空(必填)
stuAge int not null, --年齡,INT類型默認為4個字節(jié)
stuID NUMERIC(18,0), --身份證號
stuSeat int IDENTITY (1,1), --座位號,自動編號
stuAddress text --住址,允許為空,即可選輸入
)
go
if exists(select * from sysobjects where name='stuMarks') drop table stuMarks
create table stuMarks
(
ExamNo varchar(6) not null foreign key references stuInfo(stuNo) , --考號
stuNo varchar(6) not null, --學號
writtenExam int not null, --筆試成績
LabExam int not null --機試成績
)
go
if exists(select * from sysobjects where name='users') drop table users
create table users
(
userID int not null primary key identity(1,1),
userName varchar(255) not null unique,
userPWD varchar(255) not null,
userAge int,
userBirthDay datetime,
userEmail varchar(255)
)
go