wc1903036673
1、将数据分别插入表S、C、SC;(各插入两条记录) 

insert into s  
values(\'0257\',\'张一\',\'男\',25,\'CS\'), (\'0258\',\'张二\',\'男\',23,\'IS\') 

insert into c  
values(\'7\',\'web编程基础\',\'3\',5), (\'8\',\'计算机导论\',\'4\',3)

      
insert into sc  
values(\'0257\',\'7\',56), (\'0258\',\'8\',96)

 2、将表S、C、SC中的数据分别以.SQL文件或.txt文件的形式保存在磁盘上。

 

3、在表S、C、SC上练习数据的插入、修改、删除操作。

(比较在表上定义/未定义主码(Primary Key)或外码(Foreign Key)时的情况)

 

4、将表S、C、SC中的数据全部删除,再利用磁盘上备份的数据来恢复数据。

 

5、如果要在表SC中插入某个学生的选课信息(如:学号为“200215121”,课程号为“5”,成绩待定),应如何进行? 

insert into sc
(sno,cno,grade)
 
values(\'200215121\',\'5\',null) 

6、求各系学生的平均成绩,并把结果存入数据库Dept_grade 表,Dept_grade
创建如下;
create  table  Dept_grade 
( 
Sdept char(15), Avg_grade  smallint
 ) 

insert into Dept_grade

select sdept,AVG(grade)

from sc,s

where sc.sno=s.sno

group by sdept

 

 

7、将“CS”系全体学生的成绩置零;

 

update sc

set grade=\'0\'

where sno  in

(

select sno

from s

where sdept=\'cs\'

)

 

 

8、删除“CS”系全体学生的选课记录;

 

delete from sc

where sno 

in(

select  sno from s

where sdept=\'cs\'

)

9、删除学号为“0251”的相关信息;

 

delete from s

where sno=\'0251\'

10、将学号为“0251”的学生的学号修改为“S0251”;

 

update s

set sno=\'s0251\'

where sno=\'0251\'

11、把平均成绩大于分的男同学的学号和平均成绩存入另一个表S_GRADE(SNO,AVG_GRADE);

 

create table S_GRADE

(

SNO char(10),

AVG_GRADE float

)

 

insert into S_GRADE

select sno,AVG(grade)

from sc where sno

in(

select  sno from s

where ssex=\'男\')

group by sno

having AVG(grade)>80

 

12、把选修了课程名为“数据结构”的学生的各门课成绩提高%;

 

update sc

set grade=grade*1.1

where sno in

(

select sno from sc,c

where sc.cno=c.cno and cname=\'数据结构\')

 

13、把选修了“2”号课程,且成绩低于该门课程的平均成绩的学生的成绩提高%;

 

update sc

set grade=grade*1.05

where grade<

(

select  AVG(grade)

from sc

where cno=\'2\'

group by cno

)

 

14、把选修了“2”号课程,且成绩低于该门课程的平均成绩的学生成绩删除掉;

delete from sc

where cno=\'2\'and grade<

(

select AVG(grade)

from  sc

where cno=\'2\'

group by cno

)


  

  

分类:

技术点:

相关文章:

  • 2021-06-01
  • 2021-10-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-07-13
相关资源
相似解决方案