数据库建立
建立一个主文件为student的数据库,并建立一个逻辑日志
create database student
on primary
(
name = 'student_data1',
filename='D:\database_data\student_data1.mdf',
size = 20MB,
maxsize = 60MB,
filegrowth=5mb
)
log on
(
name='student_log',
filename='D:\database_data\student_log.ldf',
size=50MB,
maxsize=100MB,
filegrowth=10MB
)
数据表建立
右击新建的数据库,选择新建查询
create table Student
(
sno char(20) not null unique,
sname char(20) unique,
ssex char(1),
sage tinyint,
sdept char(16)
)
create table Course
(
con char(14) primary key,
cname char(40),
cpno char(14),
ccredit smallint,
Foreign key (cpno) references Course(con)
)
create table SC
(sno char(20),
cno char(14),
grade int default 0,
primary key(sno,cno),
foreign key(sno) references Student(sno),
foreign key(cno) references Course(con),
check(grade>=0 and grade<=100)
)