实验二 数据的查询、更新
数据库实验
实验二 数据的查询、更新
一、实验目的
)
Sage
smallint check(Sage between 15 and 45),
Sdept char(20) default 'CS',
数据库实验
insert into Student values('95001','李敏勇', '男','20', 'CS') insert into Student values('95002','刘晨', '女','19', 'IS') insert into Student values('95003','王敏', '女','18', 'MA')
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
create table SC ( )
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', '90') insert into SC values('95003','2', '55') insert into SC values('95004','2', '70')
Sno Cno
int
,
,
check (Grade between 0 and 100),
char(4)
Grade int
primary key (Sno,Cno),
foreign key (Sno) references Student(Sno), foreign key (Cno) references Course(Cno)
3、用T-SQL1) 向学生表:Student
insert into Student values('95030','谢非','男','22','CS')
2)
select Sno from Student where Sname='李敏勇' select Cno fromwhere Cname='数据库' updateset='98'
where=and=1
中谢非的记录并保存
deletefromwhere='谢非'
Student表中删除李敏勇学生的记录,为什么?能不能删除王敏, 张立两个?
delete delete from Student
from Student
where Sname='李敏勇' where Sname='王敏' and Sname='张立'
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
4、用T-SQL语句,完成下面简单的查询 1)查询全体学生的学号、姓名及年龄.
select Sno,Sname,Sage from Student
2)查询全体学生的姓名, 列名)。
select Sname,Sage,系名=LOWER(Sdept) from Student
3)查询选修了课程的学生学号
select distinct Sno from SC
4)查询信息系全体学生的姓名
select Sname from Student where Sdept='IS'
5)查询所有年龄在20
select Sname ,Sage from Student where Sage<20
6)查询年龄在20到,
select,,fromwherebetweenand
间的学生的姓名,系别及年龄
select,,fromwherenot between 19 and 23
(IS)和计算机系(CS)学生的姓名和性别
select,Ssex fromwherenot in('is','cs')
9)查询所有姓刘的学生的姓名,学号和性别
select Sname,Sno,Ssex from Student
where Sname like '刘%'
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
10)查询姓“张”且名为一个汉字的学生的姓名
select Sname from Student
where Sname like '张_'
11)查询名字中第2个字为”敏”字的学生姓名和学号
select Sname ,Sno from Student
Where Sname like '_敏%'
12)查询所有不姓刘的学生姓名
select Sname from Student
where Sname not like '刘%'
13)查询全体学生情况,结果按所在系升序排列,select * from Student
order by Sdept asc,Sage desc
14
Select top 10 percent * from Student
152
行数据,若第
Select topwithtiesfrom SC
where>=orderbydesc
select,Cno,fromcomputeSUM() by Sno
select* fromorder by Sno,Cno,Grade
compute max(Grade),min (Grade),sum(Grade),avg(Grade)by Sno
5、用T-SQL语句完成下面的查询 1)查询学生的总人数
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
select count(*) from student
2)查询选修了课程的学生人数
select count(distinct Sno) from SC
3)计算选2号课程的学生平均成绩
select AVG(Grade) from SC where Cno='2'
4)查询选修2号课程的学生最高分数
select MAX(Grade) from SC where Cno='2'
5)求各个课程号及相应的选课人数
select Cno, COUNT(Sno) from SC group by Cno
6)查询选修了2select Sno from SC group by Sno having count(*)>
7)
select.,from,,where .=.Sno and
.=.Cno
(即先修课的先修课)
http://doc.guandang.neto, second.Cpno from,Course second http://doc.guandang.neto=http://doc.guandang.neto
查询选修2号课程且成绩在90分以上(包括90分)的所有学生。
select Student.Sno,Sname from Student,SC
where Student.Sno=SC.Sno and SC.Grade>=90 and http://doc.guandang.neto='2'
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
6. 用T-SQL语句完成下面的查询
1)查询与“刘晨”在同一个系学习的学生
select Sno,Sname,Sdept from Student where Sdept IN
(select Sdept from Student
where Sname='刘晨')
2)查询选修了课程名为“数学”的学生学号和姓名
select Student.Sno,Student.Sname from Course,Student,SC
where Student.Sno=SC.Sno and http://doc.guandang.neto=http://doc.guandang.neto
and http://doc.guandang.netame='数学'
3)
select Sname,Sage from Student where Sage<any(
select Sage from Student where='IS')
and Sdept<>'IS'
4)
select Sname,fromwhere Sage<all(
selectfromwhere='CS')
and<>'CS'
selectfromwhere EXISTS
(select * from SC
where Sno=Student.Sno and Cno='2')
6)查询没有选修3号课程的学生姓名
数据库实验
实验二 数据的查询、更新
徐龙琴设计制作
select Sname from Student where NOT EXISTS (select * from SC
where Sno=Student.Sno and Cno='3')
7、用T-SQL语句完成下面的复杂查询
1)至少选修刘老师所授课程中一门课程的女学生姓名
select Sname
from Student,Course,SC
where Student.Sno=SC.Sno and http://doc.guandang.neto=http://doc.guandang.neto
and Course.Teacher like'刘%'and Student.Ssex='女'
2)检索王同学不学的课程的课程号
select Cno from Course where Cno not in
(Select http://doc.guandang.neto
from Student,SC, where Student.=.and.=http://doc.guandang.neto
…… 此处隐藏:4782字,全部文档内容请下载后查看。喜欢就下载吧 ……相关推荐:
- [行业范文]美好的法语句子
- [行业范文]描写露珠的句子
- [行业范文]精彩禅语句子图片
- [行业范文]关于满嘴谎言的句子
- [行业范文]关于安静的句子48句
- [行业范文]关于小河的句子
- [行业范文]描写稻田的句子
- [行业范文]思念好朋友的句子
- [行业范文]赞美雪的句子
- [行业范文]早上激励人心的句子
- [行业范文]失恋忧伤的句子
- [行业范文]努力积极向上的句子
- [行业范文]对工作心灰意冷的句子
- [行业范文]失恋让人心疼的句子
- [行业范文]描写珍惜青春的句子
- [行业范文]表达思念的句子简短
- [行业范文]关于父爱的句子范例
- [行业范文]浪漫的英语句子
- [行业范文]关于周末的句子
- [行业范文]思念牵挂的句子
- 有关感恩班会课件简短(二篇)(感恩班会
- 2025年初二下乡军训心得体会800字(15篇
- 关于新员工培训方案汇编(关于新员工培
- 精选高考生寒假学习计划书(精)(高考生
- 毕业实训报告心得体会(3篇)(实训报告心
- 银行工作感悟及心得范文怎么写(四篇)(
- 精选领导干部个人政治画像报告通用(七
- 精选超市11.11活动促销方案(精品超市品
- 2025年怎么做自我介绍汇总(5篇)(至2025
- 最新企业错峰生产方案(26篇)(山西企业
- 最新暑期三下乡社会实践调研报告范本(
- 最新幼儿园大班教育教学总结怎么写(最
- 最新教师节主持词小学(优秀9篇)(教师节
- 关于小学安全教育教学方案(推荐)(关于
- 员工信模板范文怎么写(五篇)(员工信息
- 最新保险销售离职申请书(十六篇)(最新
- 最新XX小学防校园欺凌工作方案怎么写(2
- 有关特岗教师辞职信范文(推荐)(特岗教
- 精选党的建设工作要点简短(党的建设的
- 如何写安康杯竞赛活动总结汇总(4篇)(安




