当前位置:Gxlcms > 数据库问题 > 2016030207 - sql50题练习(脚本)

2016030207 - sql50题练习(脚本)

时间:2021-07-01 10:21:17 帮助过:3人阅读

-- Student(S#,Sname,Sage,Ssex) 学生表
-- Course(C#,Cname,T#) 课程表
-- SC(S#,C#,score) 成绩表
-- Teacher(T#,Tname) 教师表

create table student (
   sid int(4) not null primary key auto_increment,
   sname char(20) not null,
   sage int(3) not null,
   ssex int(1) not null default ‘1‘
);

create table course(
   cid int(4) not null primary key auto_increment,
   cname char(50) not null,
   tid int(4) not null
);

create table sc(
  sid int(4) not null,
  cid int(4) not null,
  score int(3) not null
);

create table teacher(
  tid int(4) not null primary key auto_increment,
  tname char(20) not null
);

insert into student values(1,‘Tom‘,25,1), (2,‘Joan‘,19,0), (3,‘Wang‘, 41,1),  (4,‘lucy‘, 52,0),  (5,‘lili‘, 61,1);
insert into teacher values(1,‘Liming‘), (2,‘Wangshan‘), (3,‘Zhangheng‘), (4, ‘Hushi‘);
insert into course values (1,‘java‘, 2), (2,‘think‘,3), (3,‘math‘,1),(4,‘Chinese‘, 1), (5,‘high math‘,2);
insert into sc values (1,1,24),(1,2,60),(1,3,70),(1,4,90),(1,5,99);
insert into sc values (2,1,60),(2,2,80),(2,3,60),(2,4,91),(2,5,89);
insert into sc values (3,1,66),(3,2,78),(3,3,90),(3,4,78),(3,5,90);
insert into sc values (4,1,80),(4,2,34),(4,3,81),(4,4,56),(4,5,90);
insert into sc values (5,1,99),(5,2,32),(5,3,45),(5,4,12),(5,5,76);

 

2016030207 - sql50题练习(脚本)

标签:

人气教程排行