Presentation is loading. Please wait.

Presentation is loading. Please wait.

Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101.

Similar presentations


Presentation on theme: "Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101."— Presentation transcript:

1 Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101

2 In-class Exercise 1 IST2102 Transform this diagram into tables UserID Name Email SpotID Location MonthlyCost USER PARKING PARKING(SpotID, Location, MonthlyCost) USER(UserID, Name, Email, SpotID)

3 In-class Exercise 1: Notes IST2103 PARKING(SpotID, Location, MonthlyCost) USER(UserID, Name, Email, SpotID) PARKING(SpotID, Location, MonthlyCost, UserID) USER(UserID, Name, Email) Note: both options are correct, but the first one is preferred because of the minimal cardinality of SpotID is mandatory.

4 In-class Exercise 2 IST2104 Transform this diagram into tables BUILDING(BuildingName, Address) APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

5 In-class Exercise 2: Notes IST2105 BUILDING(BuildingName, Address) APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent) Notes: * A common mistake is making ApartmentID as the only primary key. (BuildingName, ApartmentID) should a composite key for APARTMENT * Another common mistake is to create a duplicate attribute BuildingName in APARTMENT. Or forget to make BuildingName as the foreign key

6 In-class Exercise 3 IST2106 CourseID CourseName Instructor StudentID StudentName Email COURSE STUDENT Transform this diagram into tables STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID)

7 In-class Exercise 3: Notes IST2107 STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID) Notes: * In REGISTRATION table, StudetID and CourseID are both primary key and foreign key. So you should give both underline and italic (wave underline in hand-written format) to them.

8 In-class Exercise 4 IST2108 USER(UserID, Name, Email) COMMENT(CommentID, Rating, Comment, UserID, MovieID) MOVIE(MovieID, MovieName, Director, Year) MovieID MovieName Director Year UserID Name Email MOVIE USER Transform this diagram into tables CommentID Rating Comment COMMENT

9 In-class Exercise 1 IST2109 PARKING(SpotID, Location, MonthlyCost) USER(UserID, Name, Email, SpotID)

10 IST21010 PARKING(SpotID, Location, MonthlyCost) USER(UserID, Name, Email, SpotID) PARKING table Column NameData Type KeyRequire d Remarks UserIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 Namechar(100)Yes Emailchar(50)No SpotIDintForeign keyYesReference: PARKING USER table Column NameData Type KeyRequire d Remarks SpotIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 Locationchar(50)Yes MonthlyCostintYesDefault: 50

11 IST21011 PARKING table Column NameData Type KeyRequire d Remarks UserIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 Namechar(100)Yes Emailchar(50)No SpotIDintForeign keyYesReference: PARKING USER table Column NameData Type KeyRequire d Remarks SpotIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 Locationchar(50)Yes MonthlyCostintYesDefault: 50 Notes: See the red parts Char is not a data type, char(50) is a data type. If you use char, you need to specify the max length When you can use other data types, do not use char. For example, it is better to use int for MonthlyCost instead of using char PARKING(SpotID, Location, MonthlyCost) USER(UserID, Name, Email, SpotID)

12 In-class Exercise 2 IST21012 Transform this diagram into tables BUILDING(BuildingName, Address) APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

13 IST21013 BUILDING table Column NameData Type KeyRequiredRemarks BuildingNameChar(20)Primary key, foreign keyYesReference: BUILDING ApartmentIDintPrimary keyYes NumberOfBedfloatYes NumberOfBathfloatYes RentfloatYes APARTMENT table Column NameData Type KeyRequiredRemarks BuildingNameChar(20)Primary keyYes AddressChar(100)YesFormat: street, city, state, zip code BUILDING(BuildingName, Address) APARTMENT(BuildingName, ApartmentID, NumberOfBedrooms, NumberofBaths, Rent)

14 IST21014 BUILDING table Column NameData Type KeyRequiredRemarks BuildingNameChar(20)Primary key, foreign keyYesReference: BUILDING ApartmentIDintPrimary keyYes NumberOfBedfloatYes NumberOfBathfloatYes RentfloatYes APARTMENT table Column NameData Type KeyRequiredRemarks BuildingNameChar(20)Primary keyYes AddressChar(100)YesFormat: street, city, state, zip code Notes: ApartmentID should NOT be a surrogate key. In real scenarios, we are using some meaningful ApartmentIDs, such as 100 or 201 instead of a meaningless system- generated id. Use float for #ofBed, #ofBath, and Rent. Because #ofBath could be 1.5 and rent could be $890.50, which are not integers.

15 In-class Exercise 3 IST21015 Transform this diagram into tables STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID)

16 IST21016 STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID) STUDENT table Column NameData Type KeyRequiredRemarks CourseIDChar(20)Primary keyYesFormat: DepartmentName + CourseNumber CourseNameChar(50)Yes InstructorChar(100)No COURSE table Column NameData Type KeyRequiredRemarks StudentIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 StudentNameChar(100)Yes EmailChar(50)No Column NameData Type KeyRequiredRemarks StudentIDintPrimary key, foreign keyYesReference: STUDENT CourseIDChar(20)Primary key, foreign keyYesReference: COURSE REGISTRATION table

17 IST21017 STUDENT table Column NameData Type KeyRequiredRemarks CourseIDChar(20)Primary keyYesFormat: DepartmentName + CourseNumber CourseNameChar(50)Yes InstructorChar(100)No COURSE table Column NameData Type KeyRequiredRemarks StudentIDintPrimary keyYesSurrogate key: initial value = 1 Increment = 1 StudentNameChar(100)Yes EmailChar(50)No Column NameData Type KeyRequiredRemarks StudentIDintPrimary key, foreign keyYesReference: STUDENT CourseIDChar(20)Primary key, foreign keyYesReference: COURSE REGISTRATION table Notes: A CourseID should not be integer, for example, “IST210” is a courseID. CourseName for IST210 is “Organization of the data”.


Download ppt "Database Design I (In-Class Exercise Answer) IST 210: Organization of Data IST2101."

Similar presentations


Ads by Google