数据库ST中有三张表,stu,course和sc表,表格信息如下图
代码如下
create database ST
use ST
create table stu
(
sno char(20) primary key,
sname char(20),
ssex char(20),
sage smallint,
sdept char(20)
)
create table course
(
cno char(20) primary key,
cname char(20),
cpno char(20),
ccredit smallint,
foreign key (cpno) references course(cno)
)
create table sc
(
sno char(20) not null,
cno char(20) not null,
grade smallint,
primary key (sno,cno),
foreign key (sno) references stu(sno),
foreign key (cno) references course(cno)
)
插入数据
/*插入学生信息数据,使用insert语句*/
insert into stu(sno,sname,ssex,sage,sdept)values('12001','李伟','男',20,'CS')
insert into stu(sno,sname,ssex,sage,sdept)values('12002','王琳','女',20,'IS')
insert into stu(sno,sname,ssex,sage,sdept)values('12003','郭文静','女',18,'MA')
insert into stu(sno,sname,ssex,sage,sdept)values('12004','周静','男',19,'IS')
insert into stu(sno,sname,ssex,sage,sdept)values('12005','李菊','女',17,'CS')
/*插入课程信息数据*/
insert into course(cno,cname,ccredit)values('2','数学',3)
insert into course(cno,cname,ccredit)values('5','C语言',4)
insert into course(cno,cname,ccredit)values('6','概率统计',3)
insert into course(cno,cname,cpno,ccredit)values('3','数据结构','5',4)
insert into course(cno,cname,cpno,ccredit)values('4','数据处理','2',2)
insert into course(cno,cname,cpno,ccredit)values('1','DB_Design','3',3)
/*插入选课信息数据*/
insert into sc(sno,cno,grade)values('12001','1',86)
insert into sc(sno,cno,grade)values('12001','2',90)
insert into sc(sno,cno,grade)values('12001','3',80)
insert into sc(sno,cno,grade)values('12001','4',75)
insert into sc(sno,cno,grade)values('12001','5',95)
insert into sc(sno,cno,grade)values('12002','2',90)
insert into sc(sno,cno,grade)values('12002','3',90)
insert into sc(sno,cno,grade)values('12002','4',90)
insert into sc(sno,cno,grade)values('12002','5',90)
insert into sc(sno,cno,grade)values('12003','2',56)
insert into sc(sno,cno,grade)values('12003','3',50)
insert into sc(sno,cno,grade)values('12003','5',90)
insert into sc(sno,cno,grade)values('12004','2',89)
insert into sc(sno,cno,grade)values('12004','4',55)
insert into sc(sno,cno,grade)values('12004','5',95)