當前位置:首頁 » 參考文獻 » 資料庫原理及設計課後答案

資料庫原理及設計課後答案

發布時間: 2021-02-26 00:15:26

資料庫系統原理及應用教程(第3版)課後習題答案!

習題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

只有這些,不知道用得到嗎

❷ 資料庫原理程序設計題,麻煩給出答案

select 學號 from score where 分數 >'70' and 分數 < '90'

❸ 跪求《資料庫系統原理與設計》課後習題答案!!

版本很多…………

❹ 資料庫原理及應用課後習題答案doc 2005 李俊山版

那個李俊山在我復們學校制教計算機專業的,隔壁軟工專業表示深受其害,雖然不是他教的,但是同宿舍友是計算機專業的,她們表示他自己出的書,他自己的答案都書上例題的答案是不一樣的,所以自求多福吧!還有就是沒有答案,他自己都沒有答案

熱點內容
塗鴉論文 發布:2021-03-31 13:04:48 瀏覽:698
手機資料庫應用 發布:2021-03-31 13:04:28 瀏覽:353
版面217 發布:2021-03-31 13:04:18 瀏覽:587
知網不查的資源 發布:2021-03-31 13:03:43 瀏覽:713
基金贖回參考 發布:2021-03-31 13:02:08 瀏覽:489
懸疑故事範文 發布:2021-03-31 13:02:07 瀏覽:87
做簡單的自我介紹範文 發布:2021-03-31 13:01:48 瀏覽:537
戰略地圖參考 發布:2021-03-31 13:01:09 瀏覽:463
收支模板 發布:2021-03-31 13:00:43 瀏覽:17
電氣學術會議 發布:2021-03-31 13:00:32 瀏覽:731