values('20050411','李华','男','cs')
insert into student(sno,sname,ssex,sdept) values('20050112','李丽','女','cs')
insert into student(sno,sname,ssex,sdept) values('20040101','张三','男','cs')
insert into student(sno,sname,ssex,sdept) values('20040501','李晨','男','cs')
insert into student(sno,sname,ssex,sdept) values('20060301','李小','女','math') insert into student(sno,sname,ssex,sdept) values('20060401','张红','女','cs')
insert into student(sno,sname,ssex,sdept) values('20070401','李金','女','is')
insert into course(cno,cname,cpno,credit) values('1','数据库','1','4')
insert into course(cno,cname,cpno,credit) values('2','数学',null,'4')
insert into course(cno,cname,cpno,credit) values('3','数据处理','2','4')
insert into course(cno,cname,cpno,credit) values('4','Pascal语言','3','4')
insert into sc(sno,cno,grade) values('20050411','1',null) insert into sc(sno,cno,grade) values('20050411','2','80') insert into sc(sno,cno,grade) values('20050112','2','79') insert into sc(sno,cno,grade) values('20040501','3',null) insert into sc(sno,cno,grade)
values('20040501','2','72') 1)列出没有成绩的学生的学号和课程号 select sc.sno,sc.cno from sc
where grade is null;
2)列出2号课程成绩在70分到80分学生的学号 select sno from sc
where cno='2' and grade between 70 and 80
1) 查询所有2005级的学生的姓名,性别和所在系 select sname,ssex,sdept from student
where sno like '2005%'
2) 查询计科系2004级全体学生的所有信息 select *
from student
where sno like '2004%'
3) 查询计科系2006级3班和4班学生的姓名和性别 select sname,ssex
from student
where sno like '200603%' or sno like '200604%'
4) 查询所有以“数”打头的课程的名称和学分 select cname,credit from course
where cname like '数%'
5) 查询数学系所有学生的姓名,性别和出生年份 select sname,ssex,2011-sage from student
where sdept='math'
6) 将course表中名为PASCAL语言的课程更名为“C语言”
update course set cname='C语言'
where cname='Pascal语言' select * from course
7) 将所有课程的学分增加1分
update course set credit=credit+1 select *from course
8)
删除没有选课成绩的选课记录
delete from sc where grade is null select * from sc
8) 删除“IS”系的所有学生信息
delete from student where sdept='is' select * from student
9) 删除所有的课程信息 delete from course where cname is not null select * from course
3. 主要仪器设备及软件:
(1)PC
(2)Microsoft SQL Server 2005
实验四 查询(多表查询,嵌套查询,分组查询)
( 验证型实验 12学时)
1. 目的要求:
实现单表和多表的普通查询和嵌套查询。包括返回单值的子查询和返回多值的子查询。使用5个聚合函数以及GROUP BY子句和HAVING子句实现分组查询. 2. 实验内容
有如下关系模式,分析每个关系模式的主码,外码,完成后面的查询 职员表:Emp(eid:integer;ename:string,salary:real)
部门表:Dept(did:integer,dname:string,managerid:integer,floornum:integer) 职员与部分的关系表:Works(eid:integer,did:integer); Works表表示:一个职员可以在多个部门工作,一个部门有多个职员
Dept表中managerid可以取值null,表示尚未任命部门经理,floornum可以取值null,表示尚未分配工作地点
用单表查询完成如下操作: 1) 输出所有员工的姓名和工资 select ename,salary from emp
2) 输出薪水少于10 000或者大于100 000的雇员的名字 select ename from emp
where salary<10000 or salary>100000
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新教学研究sql server实验一到实验七 (3)全文阅读和word下载服务。
相关推荐: