Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:*...
-
Upload
toby-cannon -
Category
Documents
-
view
219 -
download
0
Transcript of Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:*...
![Page 1: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/1.jpg)
Schema Conversion
• Create a table for each entity– 1:1 choose one side and put a foreign key– 1:* put a foreign key in many side– *:* create a table for the relation
• Relation– *:* create a table
![Page 2: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/2.jpg)
(1..1) (0..1)
Staff(staffNo, name, position, salary, branchNo, Manager)
Branch(branchNo, street, city, postcode)
Telephone (branchNo, telNo)OR
Staff(staffNo, name, position, salary,branchNo)
Branch(branchNo, street, city, postcode, staffNo)
Telephone (branchNo, telNo)
![Page 3: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/3.jpg)
(1..*) (1..1)
Staff(staffNo, name, position, salary, manages, belongs)
Branch(branchNo, street, city, postcode)
Telephone (branchNo, telNo)
Domain [manages]= Domain[Branch.branchNo]
Domain [belongs] = Domain[Branch.branchNo]
![Page 4: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/4.jpg)
staffNo fName
lName
manages
sex DOB salary branchNo
SL21 John White B005 M Oct/1/45 30000
B005
SG37 Ann Beech F Nov/10/60
12000
B003
SG14 David Ford M Mar/24/58
18000
B003
SA9 Mary Howe F 19/Feb/70
9000 B007
SG5 Susan Brand B003 F Jun/3/40 24000
B003
SL41 Julie Lee F Jun/13/65
9000 B005
Staff
BranchNo street city postcode
B005 22 Deer Rd London SW14EH
B007 16 Argyll St. Aberdeen AB2 3SU
B003 163 Main St Glasgow G11 9QX
B004 32 Manse Rd Bristol BS99 1NZ
B002 56 Clover Dr. London NW10 6EU
Branch (1..*)
(1..1)Find all the staff members who work in London.
How a relationship works in tables.
![Page 5: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/5.jpg)
PropertyForRent (propertyNo, street, city, postcode, type, rooms, rent, privateOwnerNo,
businessOwnerNo, staffNo, branchNo)
Newspaper(newspaperName)
Advertisement (newspaperName, PropertyNo, dateAdvert, cost)
PropertyForRent NewsPaper
newsPaperName {PK}
◄Advertises
(1..*) (0..*)
dateAdvertCost
propertyNo{PK}StreetCityPostcodeRoomsRentprivateOwnerNo…
Many-to-Many Case
![Page 6: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/6.jpg)
EmployeeSSN{pk}FNameMINITLNameBDateAddressSexSalary
DepartmentDnumber{pk}DnameMgrstartdateLocation[1..n]
Manages ►
◄Has1..1 1..0
1..* 1..1
ProjectPnumber{pk}PnamePlocation
Dependent
ESSN{pk}Dependent_Name{pk}SexBdateRelationship
Exercise
◄Depend
On1..1
0..*
◄Supervises
Supervisor
Supervisee
0..1
1..* In Charge of
►
Works_on ►
0..*
1..*
0..*
1..1
![Page 7: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/7.jpg)
R1
R2
R3
R4
R5
R6
R={R1, R2, R3, R4, R5, R6}
![Page 8: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/8.jpg)
Exercise
![Page 9: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/9.jpg)
Representing Relational Database Schemas
• DreamHome case study– Branch (branchNo, street, city, postcode, manager)– Staff (staffNo, fName, lName, position, sex, DOB salary,
branchNo, supervisor)– PropertyForRent (propertyNo, street, city, postcode, type,
rooms, rent, privateOwnerNo, businessOwnerNo, staffNo, branchNo)
– Client (clientNo, fName, lName, telNo, prefType, maxRent)– Registration (clientNo, branchNo, staffNo, dateJoined)– Manager(staffNo, branchNo, MgrStartDate, bonus)
![Page 10: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/10.jpg)
Schema
– Lease (leaseNo, PropertyNo, clientNo)– Preference (clientNo, preference)– Newspaper(newspaperName)– Advertisement (newspaperName, PropertyNo,
dateAdvert, cost)– PrivateOwner (privateOwnerNo, fName, lName,
address, telNo)– BusinessOwner (businessOwnerNo, businessName)
![Page 11: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/11.jpg)
IS ASSIGNED TO►
Chairs►
PROFESSOR DEPARTMENT0..11..1
1..11..N
Class Exercise
Please complete the relational schema.
PROFESSOR(PID, FName, MINIT, LName, DOB, Rank)
DEPARTMENT (DID, DName)
![Page 12: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/12.jpg)
ENROLL►STUDENTS SECTION
1..60..35
Exercise
STUDENTS (SID, FName, LName, DOB, Major[1..3], Minor)
COURSE (COURSE#, C_Name, Description)
SECTION (Section_Num, Max_size)
COURSE
Has▼
o..*
1..1
![Page 13: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/13.jpg)
Painter Painting GalleryDisplayed(1,1) (0..*)
(0..*) (1..1)Paint ► ►
Exercise
Painter (Painter_ID, FName, LName)
Paining (Painting_ID, Title, Date)
Gallery (Gallery_Name, Location)
![Page 14: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/14.jpg)
Employee SkillsLearn ►
0..* 0..*
Expert Level
Exercise
Employee (EID, FName, LName)
Skill (Skill_Name)
![Page 15: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/15.jpg)
Student ClassesTake ►
1..* 0..*
Grade
Exercise
STUDENTS (SID, FName, LName, DOB)CLASS (CLASS#, C_Name, Description)
![Page 16: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/16.jpg)
Course Section1..1 0..*
Student
Take ▼
1..*
0..*
Has ►
◄Prerequisite
0..*0..*
Grade
Exercise (Recursive and many-to-many)
STUDENTS (SID, FName, LName, DOB)COURSE (COURSE#, C_Name, Description)SECTION (Section_Num, Max_size)
![Page 17: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/17.jpg)
Consider the following relations for a database that keeps track of student enrollment in courses and the books adopted for each course:
STUDENT(SSN, Name, Major, Bdate)
COURSE(Course#, Cname, Dept)
ENROLL(SSN, Course#, Quarter, Grade)
BOOK_ADOPTION(Course#, Quarter, Book_ISBN)
TEXT(Book_ISBN, Book_Title, Publisher, Author)
Quarter(Quarter)
Draw a relational schema diagram specifying the foreign keys for this schema.
Exercise
![Page 18: Schema Conversion Create a table for each entity –1:1 choose one side and put a foreign key –1:* put a foreign key in many side –*:* create a table for.](https://reader036.fdocuments.in/reader036/viewer/2022062519/5697bfd91a28abf838caf753/html5/thumbnails/18.jpg)
StudentSSN{pk}
Name
Major
Bdate
CourseEnroll
Course# Cname Dept
Text
ISBN{pk}
Publisher
Author
Adopt
Grade
Quarter
Quarter{pk}