create database MYDB
on (name = mydbdata, filename = 'e:\MyDB\MyDB.mdf ')
log on (name = mydblog, filename = 'e:\MyDB\MyDBlog.ldf ')
use mydb
create table Student
( Sno char(9) primary key,
Sname char(20) unique,
Ssex char(2),
Sage smallint,
Sdept char(20) )
create table Course
( Cno char(4) primary key,
Cname char(20) not null,
Cpno char(4),
Credit smallint,
foreign key(Cpno) references Course(Cno))
create table SC
( Sno char(9),
Cno char(4),
Grade smallint,
primary key(Sno,Cno),
foreign key(Sno) references Student(Sno),
foreign key(Cno) references Course(Cno))
insert into student values('1','李勇','男',20,'CS')
insert into student values('2','刘晨','女',19,'CS')
insert into student values('3','王敏','女',18,'MA')
insert into student values('4','张立','男',19,'IS')
insert into Course values('1','数据库',null,4)
insert into Course values('2','数学',null,2)
insert into Course values('3','信息系统',null,4)
insert into Course values('4','操作系统',null,3)
insert into Course values('5','数据结构',null,4)
insert into Course values('6','数据处理',null,2)
insert into Course values('7','C语言',null,4)
update Course set cpno = '5' where cno = '1'
update Course set cpno = '1' where cno = '3'
update Course set cpno = '6' where cno = '4'
update Course set cpno = '7' where cno = '5'
update Course set cpno = '6' where cno = '7'
insert into sc values('1','1',92)
insert into sc values('1','2',85)
insert into sc values('1','3',88)
insert into sc values('2','2',90)
insert into sc values('2','3',80)