Presentation is loading. Please wait.

Presentation is loading. Please wait.

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.

Similar presentations


Presentation on theme: "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."— Presentation transcript:

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 the relation Relation –*:* create a table

2 (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)

3 (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]

4 staffNo fNamelNamemanagessexDOBsalarybranchNo SL21JohnWhiteB005MOct/1/4530000B005 SG37AnnBeechFNov/10/6012000B003 SG14DavidFordMMar/24/5818000B003 SA9MaryHoweF19/Feb/709000B007 SG5SusanBrandB003FJun/3/4024000B003 SL41JulieLeeFJun/13/659000B005 Staff BranchNostreetcitypostcode B00522 Deer RdLondonSW14EH B00716 Argyll St.AberdeenAB2 3SU B003163 Main StGlasgowG11 9QX B00432 Manse RdBristolBS99 1NZ B00256 Clover Dr.LondonNW10 6EU Branch (1..*) (1..1) Find all the staff members who work in London. How a relationship works in tables.

5 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..*) dateAdvert Cost propertyNo{PK} Street City Postcode Rooms Rent privateOwnerNo … Many-to-Many Case

6 Employee SSN{pk} FName MINIT LName BDate Address Sex Salary Department Dnumber{pk} Dname Mgrstartdate Location[1..n] Manages ► ◄Has 1..11..0 1..*1..1 Project Pnumber{pk} Pname Plocation Dependent ESSN{pk} Dependent_Name{pk} Sex Bdate Relationship Exercise 1..1 0..* ◄Supervises Supervisor Supervisee 0..1 1..* Works_on ► 0..* 1..* 0..* 1..1

7 R1R1 R2R2 R3R3 R4R4 R5R5 R6R6 R={R 1, R 2, R 3, R 4, R 5, R 6 }

8 Exercise

9 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)

10 Schema –Lease (leaseNo, PropertyNo, clientNo) –Preference (clientNo, preference) –Newspaper(newspaperName) –Advertisement (newspaperName, PropertyNo, dateAdvert, cost) –PrivateOwner (privateOwnerNo, fName, lName, address, telNo) –BusinessOwner (businessOwnerNo, businessName)

11 IS ASSIGNED TO► Chairs► PROFESSOR DEPARTMENT 0..11..1 1..N Class Exercise Please complete the relational schema. PROFESSOR(PID, FName, MINIT, LName, DOB, Rank) DEPARTMENT (DID, DName)

12 ENROLL► STUDENTS SECTION 1..6 0..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

13 PainterPainting Gallery Displayed (1,1)(0..*) (1..1) Paint ► ► Exercise Painter (Painter_ID, FName, LName) Paining (Painting_ID, Title, Date) Gallery (Gallery_Name, Location)

14 EmployeeSkills Learn ► 0..* Expert Level Exercise Employee (EID, FName, LName) Skill (Skill_Name)

15 StudentClasses Take ► 1..*0..* Grade Exercise STUDENTS (SID, FName, LName, DOB) CLASS (CLASS#, C_Name, Description)

16 Course Section 1..10..* Student Take ▼ 1..* 0..* Has ► ◄Prerequisite 0..* Grade Exercise (Recursive and many-to-many) STUDENTS (SID, FName, LName, DOB) COURSE (COURSE#, C_Name, Description) SECTION (Section_Num, Max_size)

17 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

18 Student SSN{pk} Name Major Bdate Course Enroll Course#Cname Dept Text ISBN{pk} Publisher Author Adopt Grade Quarter Quarter{pk}


Download ppt "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."

Similar presentations


Ads by Google