数据库原理与应用教程第4版课后习题答案(何玉洁)

数据库原理与应用教程第4版课后习题答案(何玉洁),第1张

第一题:

答案:

第二题:

答案:

第三题:

答案:

第四题:

答案:

扩展资料

这部分内容主要考察的是数据库系统的知识点:

数据库系统为适应数据处理的需要而发展起来的一种较为理想的数据处理系统,也是一个为实际可运行的存储、维护和应用系统提供数据的软件系统,是存储介质 、处理对象和管理系统的集合体。

数据库系统通常由软件、数据库和数据管理员组成。其软件主要包括 *** 作系统、各种宿主语言、实用程序以及数据库管理系统。数据库由数据库管理系统统一管理,数据的插入、修改和检索均要通过数据库管理系统进行。数据管理员负责创建、监控和维护整个数据库,使数据能被任何有权使用的人有效使用。数据库管理员一般是由业务水平较高、资历较深的人员担任。

数据库系统的个体含义是指一个具体的数据库管理系统软件和用它建立起来的数据库;它的学科含义是指研究、开发、建立、维护和应用数据库系统所涉及的理论、方法、技术所构成的学科。在这一含义下,数据库系统是软件研究领域的一个重要分支,常称为数据库领域。

数据库系统是为适应数据处理的需要而发展起来的一种较为理想的数据处理的核心机构。计算机的高速处理能力和大容量存储器提供了实现数据管理自动化的条件。

borrower:

create table borrower(

借书证号 char[5] primary key,

姓名 char[20] not null,

系名 char[10],

班级 char[10])

create table loans(

借书证号 char[5],

图书登记号 char[6],

结束日期 DATE,

primary key(借书证号,图书登记号),

foreign key(借书证号) reference borrower(借书证号),

foreign key(图书登记号 reference books(图书登记号))

create table books(

索书号 char[10],

书名 char[20],

图书登记号 char[6] primary key,

出版社 char[20],

价格 smallint))

(1)

select borrower.借书证号,姓名,系名,temp.total as 借书数量

from borrower,(select 借书证号,count(图书登记号) as total

from loans group by 借书证号

where tatal>5 as temp(借书证号,total))

(2)

select borrower.姓名,系名,书名,结束日期

from borrower,loans,books

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 书名 in(selcet 书名

from borrower,loans,books

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 姓名='赵垒')

(3)

create view SB

as

select borrower.借书证号,姓名,班级,books.图书登记号,书名,出版社

,借书日期

from borrower,book,loans

where borrower.借书证号=loans.借书证号

and books.图书登记号=loans.图书登记号

and 系名='信息系'

1

create table student(

sno char[10] primary key,

sname char[20] not null,

ssex char[2],

sage smallint check( sage between 16 and 30),

sdept char[4])

create table course(

cno char[10] primary key,

cname char[20] not null,

cteacher char[20])

create table sc(

sno char[10],

cno char[10],

grade smallint check(grade is null or grade between 0 and

100),

primary key(sno,cno)

foreign key sno reference student(sno),

foreign key cno reference course(cno))

2

insert into student values('102','李四','男',16,'数学')

下同

insert into course values('203',' *** 作系统','程羽')

下同

insert into sc values('101','203',82)

下同

3

(1) select cname,grade

from sc,student,course

where student.sno=sc.sno and course.cno=sc.cno

and sname='张三'

(2) select sname from student

where sno in(select sno from sc x

where not exists(

select * from sc y

where x.sno=y.sno

and y.grade<60))

(3) select cname,sname,grade

from student,course sc,(select cno,max(grade) from sc group by cno

as temp(cno,max))

where student.sno=sc.sno and course.cno=sc.cno

and grade=max and course.cno=temp.cno

4

delete * from sc where grade<60

5

update sc

set grade=(select avg(grade) from sc where cno='203')

where sno=105

仅供参考

习题5第5题p148

create database 职工_社团

use 职工_社团

create table 职工(

职工号 char(10) primary key,

姓名 char(8),

年龄 smallint default 20,

性别 char(20),

constraint C1 check (性别 in ('男','女')))

create table 社会团体(

编号 char(10) primary key,

名称 char(8),

负责人 char(10),

活动地点 char(20),

constraint C2 foreign key (负责人) references 职工 (职工号))

create table 参加(

职工号 char(10),

编号 char(10),

参加日期 smalldatetime,

constraint C3 primary key (职工号,编号),

constraint C4 foreign key (职工号) references 职工 (职工号),

constraint C5 foreign key (编号) references 社会团体 (编号))

(2)

create view 社团负责人(编号,名称,负责人职工号,负责人姓名,负责人性别)

as select 社会团体.编号,社会团体.名称,社会团体.负责人, 职工.职工号,职工.性别

from 职工,社会团体,参加

where 社会团体.编号=参加.编号 and 职工.职工号=参加.职工号

create view 参加人情况(职工号,姓名,社团编号,社团名称,参加日期)

as select 参加.职工号,姓名,社会团体.编号,名称,参加日期

from 职工,社会团体,参加

where 职工.职工号=参加.职工号 and 参加.编号=社会团体.编号

(3)

select distinct 职工.职工号,姓名

from 职工,社会团体,参加

where 职工.职工号=参加.职工号 and 参加.编号=社会团体.编号

and 社会团体.名称 in('歌唱队','篮球队')

(4)

select *

from 职工

where not exists (select *

from 参加

where 参加.职工号=职工.职工号)

(5)

select * from 职工

where not exists

(select *

from 社会团体

where not exists

(select *

from 参加

where 参加.职工号=职工.职工号 and 参加.编号=社会团体.编号))

(6)

select 职工号

from 职工

where not exists (select *

from 参加 参加1

where 参加1.职工号='001'and not exists

(select *

from 参加 参加2

where 参加2.编号=参加1.编号 and 参加2.职工号=职工.职工号))

(7)

select 编号,count(职工号) as 参加人数

from 参加

group by 编号

(8)

select TOP 1 名称,count(*) 参加人数

from 参加,社会团体

where 参加.编号=社会团体.编号

group by 名称

order by 参加人数 desc

(9)

select distinct 社会团体.名称,职工.姓名 as 负责人

from 职工,社会团体,参加

where 社会团体.编号=参加.编号

and 社会团体.负责人=职工.职工号

and 参加.编号 in(select 参加.编号

from 参加

group by 参加.编号 having count(参加.编号)>100)

(10)

grant select,insert,delete on 社会团体 to 李平

with grant option

grant select,insert,delete on 参加 to 李平

with grant option

习题6第9题p212

create database 学生选课

use 学生选课

create table 学生(

学号 char(10) primary key,

姓名 char(10),

性别 char(10),

constraint C1 check (性别 in ('男','女')),

年龄 smallint default 20,

所在系 char(20))

create table 课程(

课程号 char(10) primary key,

课程名 char(20),

先行课 char(20))

create table 选课(

学号 char(10),

课程号 char(10),

成绩 smallint,

constraint D1 primary key (学号,课程号),

constraint D2 foreign key (学号) references 学生(学号),

constraint D3 foreign key (课程号) references 课程(课程号))

create index student_ind on 学生(学号)

create index class_ind on 课程(课程号)

create index select_ind on 选课(学号,课程号)

create rule value_rule as @value in ('男','女')

go

exec sp_bindrule 'value_rule','学生.性别'

go

create default 性别缺省 as '男'

go

exec sp_bindefault '性别缺省','学生.性别'

go

create trigger 选课插入更新 on 选课

for insert,update

as if (select count(*)

from 学生,inserted,课程

where 学生.学号=inserted.学号 and 课程.课程号=inserted.课程号)=0

rollback transaction

go

create trigger delete_all on 学生

for delete

as delete 选课

from 选课,deleted

where 选课.学号=deleted.学号

go

select 所在系,count(学号)as 学生人数

from 学生

group by 所在系

order by 所在系

compute count(所在系),sum(count(学号))

select *

from 学生 inner join 选课 on 学生.学号=选课.学号

go

select *

from 学生 left outer join 选课 on 学生.学号=选课.学号

go

select *

from 学生 right outer join 选课 on 学生.学号=选课.学号

go

select 选课.学号,学生.姓名,

学习情况=case

when avg(成绩)>=85 then '好'

when avg(成绩)>=75 and avg(成绩)<85 then '较好'

when avg(成绩)>=60 and avg(成绩)<75 then '一般'

when avg(成绩)<60 then '较差'

end

from 学生,选课

where 学生.学号=选课.学号

group by 选课.学号,姓名

go

只有这些,不知道用得到吗


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9992058.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-04
下一篇 2023-05-04

发表评论

登录后才能评论

评论列表(0条)

保存