1.建数据库
use master
go
if exists(select * from sysdatabases where name='MySchool')
drop database MySchool
create database MySchool
on primary
( name='MySchool_data',
filename='C:\数据库\MySchool_data.mdf',
size=10Mb,
filegrowth=20%
)
log on(
name='MySchool_log',
filename='c:\数据库\MySchool_log.ldf',
size=3Mb,
maxsize=20MB,
filegrowth=1Mb
)
2.建表
--添加表
if exists(select * from sysobjects where name='Student')
drop table Student
create table Student
(
StudentNo int not null,
LoginPwd nvarchar(50) not null,
)
--添加各种约束
alter table Student
add constraint PK_StudentNo primary Key (StudentNo)
alter table Student
add constraint UQ_StuID unique(IdentityCard)
alter table Student
add constraint DF_StuAddress default('地址不详') for [Address]
alter table Student
add constraint CK_BornDate Check(BornDate>='1980-01-01')
alter table Student
add constraint FK_GradeId foreign key(GradeID) references Grade(GradeID)