內(nèi)連接:inner join, natural join 就是典型的內(nèi)連接。內(nèi)連接不保留未匹配元組的連接。
例如:student表中有一個(gè)ID為00000的學(xué)生,但沒有選課所以,takes表中不會出現(xiàn)ID00000园蝠。因此natural join后的結(jié)果也就不會有ID00000。這就是內(nèi)連接糕伐。
外連接:
left outer join:只保留出現(xiàn)在左外連接運(yùn)算之前(左邊)的關(guān)系中的元組砰琢。
right outer join:只保留出現(xiàn)在左外連接運(yùn)算之前(右邊)的關(guān)系中的元組。
?full outer join:保留出現(xiàn)在兩個(gè)關(guān)系中的元組良瞧。
where和on的不同:where謂詞返回一個(gè)true的條件后進(jìn)行篩選。
select * from student natural left outer join takes where/on student.ID = takes.ID;
where的話训唱,student.ID=takes.ID是一個(gè)條件褥蚯,返回true。當(dāng)takesID中沒有00000時(shí)况增,自然就返回false赞庶,所以這條元組就被過濾了。on則不會過濾澳骤。
沒有使用outer前綴的join則默認(rèn)為inner join
視圖定義(view):create view faculty as select ID, name, dept_name from instructor;
視圖存儲的是查詢表達(dá)式而非執(zhí)行結(jié)果歧强。
對視圖進(jìn)行修改將會影響到邏輯層次的數(shù)據(jù)庫。
事務(wù)有時(shí)候會違反完整性約束为肮,所以通常用關(guān)鍵詞initally deferred來聲明約束是可延遲的摊册,指明約束的檢查被延遲到該事物結(jié)束時(shí)執(zhí)行。
Mysql drop constraint:
alter table instructor drop foreign key instructor_ibfk_1; 通過show create table instructor知道foreign key
add constraint:
alter table instructor add foreign key instructor(dept_name) references department(dept_name) on delete cascade;
type & domain
create type 和 create domain颊艳,創(chuàng)建type用來檢測一些賦值錯(cuò)誤茅特,如將美元賦值給英鎊。
兩者有明顯的差別棋枕,具體的情況應(yīng)該用得比較少白修。
數(shù)據(jù)庫授權(quán):
grant select on instructor to zachary;
revoke select on instructor to zachary; 收回
角色(role)的概念:create role instructor,角色的概念用來授權(quán)重斑,授權(quán)給role兵睛,只要將需要這個(gè)權(quán)限的任務(wù)增加該role標(biāo)示即可。
grant select on instructor to zachary with grant option:表示zachary可以將權(quán)限授予其他人
默認(rèn)的權(quán)限收回是級聯(lián)收回,即同時(shí)收回被收回用戶授予給其他的人的權(quán)限祖很。
所以授權(quán)最好是角色授權(quán)而不是用戶授權(quán)笛丙。
習(xí)題:
4.1.d. select dept_name, count(ID) from department natural left outer join instructor group by dept_name;
4.2
mysql> select * from student natural join takes
-> union
-> select ID, name, dept_name, tot_cred, NULL, NULL, NULL, NULL, NULL from student s where not exists
-> (select ID from takes T where T.ID = S.ID)
-> ;
4.8
a. mysql> select ID, name, sec_id, semester, year, time_slot_id, count(distinct building, room_number)
-> from instructor natural join teaches natural join section group by (ID, name, sec_id, semester, year, time_slot_id)
-> having count(distinct building, room_number) > 1;
OLAP:
度量屬性(measure attribute):這個(gè)屬性度量了某個(gè)值,可以在其上進(jìn)行聚集操作突琳,比如sale的quantity屬性若债。
維度屬性(dimension attribute):定義度量屬性以及度量屬性的匯總可以在其上進(jìn)行觀察的各個(gè)維度。比如sale的item_name,size等拆融。