继前两次的实验,本次实验以熟练掌握利用select语句进行各种查询操作:单表查询、多表连接及查询、嵌套查询、集合查询等,巩固数据库查询操作。
下面就跟着小编一起练习吧!
在实验一创建并插入数据的表(Student, Course,SC,Teacher,TC)的基础上,完成以下操作。
(1)将教师‘罗莉'的名字改为‘罗莉莉'。
update Teacher set tname='罗莉莉' where tname='罗莉'
(2)将两个同学(数据自己临时设置,用后即删除)的两门课程的成绩以运行sql程序文件的形式插入score表中。该题用以验证、理解和掌握关系模型的完整性规则;
插入:
insert into Score(sno,cno,grade) values ('04261006','C003','64')
insert into Score(sno,cno,grade) values('04261007','C004','79')
查询:
select sno 学号,cno 课程号,grade 分数from Score where sno=04261006 or sno=04261007;
删除:
delete from Score where sno=04261006 or sno=04261007;
(3)求每门课的平均成绩,并把结果存入average表(自行设计并创建);
CREATE TABLE average
(
cno CHAR(8),
avscore numeric(5,2),
constraint a1 primary key (cno),
constraint a2 foreign key (cno) references Course(cno),
)
insert into average(cno,avscore)
select distinct cno ,avg(grade) from Score group by cno
(4)将学生“马丽”的年龄改为24;
Update Student set 2014-year(Sbirth) 年龄 where Sname=' 马丽'
(5)将所有学生的szipcode属性列值填补上;
update Student set szipcode='221000'
(6)将average表中的所有课程的平均成绩置零;
update average set avscore='0'
(7)删除average表中的课程号为‘C007'的平均成绩记录;
delete from average where cno='C007'
(8)删除所有average表中平均成绩记录;
delete from average;
(9)建立一个临时学生信息表(tstudent),删除该表中的学号含‘101'的所有学生记录。
create table tstudent ( Sno char(8) primary key, Sname varchar(8) unique );
Delete from tstudent where Sno like '001011%';
(10)查询全体学生的学号与姓名;
select sno 学号,sname 姓名from Student
(11)查询全体学生的学号、姓名、所属系;
select sno 学号,sname 姓名,sdept 系from Student
(12)查询全体学生的详细记录;
select * from Student
(13)查询全体学生的姓名及其年龄;
|