Скачать презентацию Keys Super Key a set of Скачать презентацию Keys Super Key a set of

2ad5a1cca598dd87caa3797d2b6b2b69.ppt

  • Количество слайдов: 21

Keys ® Super. Key ® a set of attributes whose values together uniquely identify Keys ® Super. Key ® a set of attributes whose values together uniquely identify a tuple in a relation ® Candidate Key ® a superkey for which no proper subset is a superkey…a key that is minimal. ® Can be more than one for a relation ® Primary Key ® a candidate key chosen to be the main key for the relation. ® One for each relation ® Keys can be composite

e. g. : Staff(lecturer, roomno, appraiser) SK = {lecturer, roomno, appraiser}, {lecturer, roomno}, {lecturer, e. g. : Staff(lecturer, roomno, appraiser) SK = {lecturer, roomno, appraiser}, {lecturer, roomno}, {lecturer, appraiser}, {roomno, appraiser}, {lecturer} and {roomno} CK = {lecturer} and {roomno} PK = {lecturer}

Foreign Key ®a (set of) attribute(s) in a relation that exactly matches a (primary) Foreign Key ®a (set of) attribute(s) in a relation that exactly matches a (primary) key in another relation the names of the attributes don’t have to be the same but must be of the same domain ® a foreign key in a relation A matching a primary key in a relation B represents a ® ® many: one relationship between A and B Student(studno, name, tutor, year) Staff(lecturer, roomno, appraiser)

Relationship -v- Relation hons name m STUDENT REG studno 1 SCHOOL faculty Relationship “an Relationship -v- Relation hons name m STUDENT REG studno 1 SCHOOL faculty Relationship “an association between several entities represented by a Relationship Type of which there will be many Relationship Instances” STUDENT (studno, name, hons) SCHOOL(hons, faculty) Relation (table)

Relationship -v- Relation courseno name m ENROL STUDENT studno exammark n COURSE subject ENROL Relationship -v- Relation courseno name m ENROL STUDENT studno exammark n COURSE subject ENROL Relationship STUDENT (studno, name) ENROL(studno, courseno, exammark) COURSE(courseno, subject) ENROL Relation

Joins STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF Joins STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26 e. g. , get studno, name and tutor’s roomno for each student

STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26

STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26 studno, name, roomno (STUDENT STAFF) studno name s 1 s 2 s 3 jones brown smith tutor lecturer roomno bush kahn bush kahn bush IT 206 2. 26 tutor=lecturer SELECT FROM STUDENT a, STAFF b WHERE

STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26 studno, name, roomno (STUDENT STAFF) studno name s 1 s 2 s 3 jones brown smith tutor lecturer roomno bush kahn bush kahn bush IT 206 2. 26 tutor=lecturer SELECT FROM STUDENT a, STAFF b WHERE a. tutor=b. lecturer

STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26 studno, name, roomno (STUDENT STAFF) studno name s 1 s 2 s 3 jones brown smith tutor=lecturer tutor lecturer roomno SELECT bush kahn bush kahn bush IT 206 2. 26 a. studno, a. name, b. roomno FROM STUDENT a, STAFF b WHERE a. tutor=b. lecturer

STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor STUDENT studno name s 1 jones s 2 brown s 3 smith STAFF tutor bush kahn goble lecturer kahn bush roomno IT 206 2. 26 studno=‘s 1’( studno, name, roomno (STUDENT STAFF)) studno name s 1 s 2 s 3 jones brown smith tutor=lecturer tutor lecturer roomno SELECT bush kahn bush kahn bush IT 206 2. 26 a. studno, a. name, b. roomno FROM STUDENT a, STAFF b WHERE a. tutor=b. lecturer and

Join as Path m Hotel Residences 1 hotelid Get hotels and their regions Resort Join as Path m Hotel Residences 1 hotelid Get hotels and their regions Resort m Reg. Loc resort SELECT HOTEL (hotelid, name, resort) REGION(region, country) Region region FROM RESORT(resort, region) 1 WHERE

m Hotel Residences 1 hotelid Get hotels and their regions Resort m Reg. Loc m Hotel Residences 1 hotelid Get hotels and their regions Resort m Reg. Loc resort 1 Region region SELECT FROM RESORT(resort, region) HOTEL, RESORT, REGION(region, country) WHERE HOTEL (hotelid, name, resort)

hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions Resort m Reg. Loc resort 1 Region region SELECT FROM RESORT(resort, region) HOTEL, RESORT, REGION(region, country) WHERE HOTEL (hotelid, name, resort) hotel. resort=resort. resor t

hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions Resort resort. region=region. re gion m Reg. Loc resort 1 Region region SELECT FROM RESORT(resort, region) HOTEL, RESORT, REGION(region, country) WHERE HOTEL (hotelid, name, resort) hotel. resort=resort. resor t and

hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions hotel. resort=resort. reso rt m Hotel Residences 1 hotelid Get hotels and their regions HOTEL (hotelid, name, resort) RESORT(resort, region) REGION(region, country) Resort resort. region=region. re gion m Reg. Loc 1 resort Region region SELECT hotel. name, region FROM HOTEL, RESORT, REGION WHERE hotel. resort=resort. resor

Sub and Super-Types (Classes) STUDENT given undergraduate family name studno STUDENT jones d year Sub and Super-Types (Classes) STUDENT given undergraduate family name studno STUDENT jones d year brown postgraduate undergraduate thesis title postgraduate

Sub and Super-Types (Classes) PERSON given staff family name PERSON o staff brown student Sub and Super-Types (Classes) PERSON given staff family name PERSON o staff brown student

Sub and Super-Types (Classes) STAFF technical STAFF smith o technical admin Sub and Super-Types (Classes) STAFF technical STAFF smith o technical admin

Referential Integrity ® Student(studno, name, tutor, year) ® Staff(lecturer, roomno, appraiser) ® CASCADE ® Referential Integrity ® Student(studno, name, tutor, year) ® Staff(lecturer, roomno, appraiser) ® CASCADE ® delete all matching foreign key tuples e. g. STUDENT ® RESTRICT ® can’t delete primary key tuple STAFF whilst a foreign key tuple STUDENT matches ® NULLIFY ® foreign key STUDENT. tutor set to null if the foreign key ids allowed to take on null

Lab Extensions ® Completed work must be handed in by 9: 30 on the Lab Extensions ® Completed work must be handed in by 9: 30 on the day of the subsequent lab!