创建3个表,
create Table Student(
sno char(10) not null,
sname varchar(20),
sage smallint,
ssex char(1),
sdept char(2),
primary key(sno),
check(ssex in('M','F')))
Create Table Course(
cno char(10) not null,
cname varchar(20),
cpno char(10) null,
credit smallint,
primary key (cno),
foreign key (cpno) references Course)
Create Table SC(
sno char(10) not null,
cno char(10) not null,
grade smallint,
primary key(sno,cno),
foreign key (sno) references Student,
foreign key (cno) references Course,
check(grade>=0 and grade<=100)
)
insert into Student(sno,sname,sage,ssex,sdept)
values('95001','李勇',20,'M','CS');
insert into Student(sno,sname,sage,ssex,sdept)
values('95002','刘晨',19,'F','IS');
insert into Student(sno,sname,sage,ssex,sdept)
values('95003','王敏',18,'F','MA');
insert into Student(sno,sname,sage,ssex,sdept)
values('95004','张立',19,'M','IS');
insert into Course(cno,cname,cpno,credit)
values('2','数学',null,2);
insert into Course(cno,cname,cpno,credit)
values('6','数据处理',null,2);
insert into Course(cno,cname,cpno,credit)
values('7','PASCAL语言','6',4);
insert into Course(cno,cname,cpno,credit)
values('4','操作系统','6',3);
insert into Course(cno,cname,cpno,credit)
values('5','数据结构','7',4);
insert into Course(cno,cname,cpno,credit)
values('1','数据库','5',4);
insert into Course(cno,cname,cpno,credit)
values('8','信息系统','1',4);
insert into SC values('95001','1',92);
insert into SC values('95001','2',85);
insert into SC values('95001','3',88);
insert into SC values('95002','2',50);
insert into SC values('95002','3',80);
select * from Student;
select * from SC;
select * from Course;
select * from Student where sname like'李勇';
select * from Course where cname like'数%';
insert into Student(sno,sname,sage,ssex,sdept)
values('95006','张_lo',19,'M','IS');
select * from Student where sname like'张t_%' escape't'
insert into SC values('95005','2',50);
insert into SC values('95005','4',56);
select sname,sno from student where sno in
(select sno from SC where grade <60);
select count(*)from Student GROUP BY sname
select avg(grade) from SC where cno='2'
select * from sc;
select sno from sc group by sno
select sno from sc group by sno having count(*)>1