當前位置:首頁 » 操作系統 » 資料庫系統原理習題答案

資料庫系統原理習題答案

發布時間: 2022-07-02 04:46:46

資料庫系統原理及應用教程(第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

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

❷ 資料庫原理與應用教程第4版課後習題答案(何玉潔)

第一題:

(2)資料庫系統原理習題答案擴展閱讀

這部分內容主要考察的是資料庫系統的知識點:

資料庫系統為適應數據處理的需要而發展起來的一種較為理想的數據處理系統,也是一個為實際可運行的存儲、維護和應用系統提供數據的軟體系統,是存儲介質 、處理對象和管理系統的集合體。

資料庫系統通常由軟體、資料庫和數據管理員組成。其軟體主要包括操作系統、各種宿主語言、實用程序以及資料庫管理系統。資料庫由資料庫管理系統統一管理,數據的插入、修改和檢索均要通過資料庫管理系統進行。數據管理員負責創建、監控和維護整個資料庫,使數據能被任何有權使用的人有效使用。資料庫管理員一般是由業務水平較高、資歷較深的人員擔任。

資料庫系統的個體含義是指一個具體的資料庫管理系統軟體和用它建立起來的資料庫;它的學科含義是指研究、開發、建立、維護和應用資料庫系統所涉及的理論、方法、技術所構成的學科。在這一含義下,資料庫系統是軟體研究領域的一個重要分支,常稱為資料庫領域。

資料庫系統是為適應數據處理的需要而發展起來的一種較為理想的數據處理的核心機構。計算機的高速處理能力和大容量存儲器提供了實現數據管理自動化的條件。

熱點內容
html5android教程視頻下載 發布:2024-04-26 03:09:59 瀏覽:866
伺服器的描述是什麼 發布:2024-04-26 03:08:32 瀏覽:393
個人加密 發布:2024-04-26 03:01:23 瀏覽:519
linuxusbgadget 發布:2024-04-26 02:52:54 瀏覽:303
我的世界空島世界伺服器地址 發布:2024-04-26 01:39:08 瀏覽:248
尼爾機械紀元加密 發布:2024-04-26 01:37:11 瀏覽:867
在控制台輸出sql語句 發布:2024-04-26 01:08:12 瀏覽:432
動畫java 發布:2024-04-26 01:02:40 瀏覽:12
得力文件夾5302 發布:2024-04-26 00:21:32 瀏覽:91
您的個人文件夾 發布:2024-04-26 00:03:12 瀏覽:68