Download presentation
Presentation is loading. Please wait.
Published byBrian Matthews Modified over 8 years ago
1
DATABASE DESIGN II IST 210: Organization of Data IST210 1
2
Previously IST210 2 EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone, LockerID) LOCKER(LockerID, LockerRoom, LockerSize) EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone) LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID) N:M add an intersection table EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone) LOCKER(LockerID, LockerRoom, LockerSize) ASSIGNMENT(EmployeeID, LockerID) EMPLOYEE(EmployeeID, Name, OfficeNumber, OfficePhone) LOCKER(LockerID, LockerRoom, LockerSize, EmployeeID) 1:N add a foreign key to the many-side table 1:1 add a foreign key to either table or
3
Previously: Exercise 3 IST210 3 Transform this diagram into tables STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID)
4
IST210 4 STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID) STUDENT table Column Name Data TypeKeyRequiredRemarks CourseID CourseName Instructor COURSE table Column Name Data Type KeyRequiredRemarks StudentID StudentName Email Column Name Data Type KeyRequiredRemarks StudentID CourseID REGISTRATION table In-class Exercise 3
5
IST210 5 STUDENT(StudentID, StudentName, Email) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID) STUDENT table Column Name Data TypeKeyRequiredRemarks CourseIDChar(20)Primary key YesFormat: DepartmentName + CourseNumber CourseNameChar(50)Yes InstructorChar(100)No COURSE table Column Name Data TypeKeyRequiredRemarks StudentIDintPrimary key YesSurrogate key: initial value = 1 Increment = 1 StudentNameChar(100)Yes EmailChar(50)No Column Name Data Type KeyRequiredRemarks StudentIDintPrimary key, foreign keyYesReference: STUDENT CourseIDChar(20)Primary key, foreign keyYesReference: COURSE REGISTRATION table
6
IST210 6 STUDENT table Column Name Data TypeKeyRequiredRemarks CourseIDChar(20)Primary key YesFormat: DepartmentName + CourseNumber CourseNameChar(50)Yes InstructorChar(100)No COURSE table Column Name Data Type KeyRequiredRemarks StudentIDintPrimary key YesSurrogate key: initial value = 1 Increment = 1 StudentNameChar(100)Yes EmailChar(50)No Column Name Data 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”.
7
COURSE REGISTRATION SYSTEM Case study IST210 7
8
8 StudentID Name Email STUDENT StudentID CourseID Grade GRADE DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE Complete E-R Diagram
9
IST210 9 StudentID Name Email STUDENT DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE
10
IST210 10 STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) Primary key: use underline Foreign key: italic font (I use red color here to emphasize the foreign key. You don’t need to make it a different color in the assignment.) StudentID Name Email STUDENT DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE
11
IST210 11 StudentID Name Email STUDENT StudentID CourseID Grade GRADE CourseID CourseName Instructor COURSE STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName)
12
IST210 12 STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade) StudentID Name Email STUDENT StudentID CourseID Grade GRADE CourseID CourseName Instructor COURSE
13
IST210 13 STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
14
IST210 14 STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade) Column NameData TypeKeyRequiredRemarks DepartName Building Phone DEPARTMENT We start with the table without a foreign key. STUDENT and COURSE need to know DepartName type. GRADE need to know StudentID and CourseID type. So we should first specify DEPARTMENT table, then STUDENT and COURSE, and finally GRADE table.
15
IST210 15 Column NameData TypeKeyRequire d Remarks DepartNameChar(50)Primary keyYes BuildingChar(100)Yes PhoneChar(12)NoFormat: ###-###- #### DEPARTMENT We start with the table without a foreign key. STUDENT and COURSE need to know DepartName type. GRADE need to know StudentID and CourseID type. So we should first specify DEPARTMENT table, then STUDENT and COURSE, and finally GRADE table. STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
16
IST210 16 Column Name Data Type KeyRequire d Remarks StudentID Name Email DepartName STUDENT STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
17
IST210 17 Column Name Data Type KeyRequire d Remarks StudentIDintPrimary key yesSurrogate key: initial value = 1, increment = 1 NameChar(100)yes EmailChar(100)no DepartNameChar(50)Foreign key yesReference: DEPARTMENT STUDENT Must be the same as data type in DEPARTMENT Determined by the minimum cardinality STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
18
IST210 18 Column Name Data Type KeyRequire d Remarks CourseID CourseName Instructor DepartName COURSE STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
19
IST210 19 Column Name Data Type KeyRequire d Remarks CourseIDChar(10)Primary key yesFormat: Department name + number CourseNameChar(100)yes InstructorChar(100)no DepartNameChar(50)Foreign key yesReference: DEPARTMENT COURSE Must be the same as data type in DEPARTMENT Determined by the minimum cardinality STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
20
IST210 20 Column Name Data Type KeyRequiredRemarks StudentID CourseID Grade GRADE STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
21
IST210 21 STUDENT(StudentID, Name, Email, DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade) Column Name Data Type KeyRequiredRemarks StudentIDIntPrimary key, foreign key yesReference: STUDENT CourseIDChar(10)Primary key, foreign key yesReference: COURSE GradeChar(2)no GRADE Must be the same as data type in STUDENT and COURSE Remarks here should be the reference tables, not the surrogate key
22
LISA’S BOOKSTORE Case study IST210 22
23
IST210 23 BookID Title Year BOOK PurchaseID Price Date PURCHASE AuthorID Name Country PublisherName Location Phone AUTHOR PUBLISHER EmailAddress Name Address Phone CUSTOMER EventID Name Date Type EVENT Complete E-R Diagram
24
IST210 24 BookID Title Year BOOK AuthorID Name Country PublisherName Location Phone AUTHOR PUBLISHER
25
IST210 25 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) BookID Title Year BOOK AuthorID Name Country AUTHOR PublisherName Location Phone PUBLISHER
26
IST210 26 BookID Title Year BOOK PurchaseID Price Date PURCHASE EmailAddress Name Address Phone CUSTOMER PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID)
27
IST210 27 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) BookID Title Year BOOK PurchaseID Price Date PURCHASE EmailAddress Name Address Phone CUSTOMER
28
IST210 28 EmailAddress Name Address Phone CUSTOME R EventID Name Date Type EVENT PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone)
29
IST210 29 EmailAddress Name Address Phone CUSTOMER EventID Name Date Type EVENT PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID)
30
IST210 30 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) E-R diagram is transformed into a database with 8 tables
31
IST210 31 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequire d Remarks PublisherName Location Phone PUBLISHER
32
IST210 32 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks PublisherNameChar(50)Primary keyYes LocationChar(100)No PhoneChar(12)NoFormat: ###-###- #### PUBLISHER
33
IST210 33 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks BookID Title Year PublisherName BOOK
34
IST210 34 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks BookIDintPrimary key YesSurrogate key, initial value = 1, increment =1 TitleChar(100)Yes YearChar(4)No PublisherNameChar(50)Foreign key YesReference: PUBLISHER BOOK
35
IST210 35 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks AuthorID Name Country AUTHOR
36
IST210 36 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks AuthorIDintPrimary key YesSurrogate key, initial value = 1, increment =1 NameChar(100)Yes CountryChar(20)No AUTHOR
37
IST210 37 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks BookID AuthorID BOOK_AUTHOR
38
IST210 38 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks BookIDintPrimary key, foreign key YesReference: BOOK AuthorIDintPrimary key, foreign key YesReference: AUTHOR BOOK_AUTHOR
39
IST210 39 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EmailAddress Name Address Phone CUSTOMER
40
IST210 40 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EmailAddressChar(50)Primary key Yes NameChar(50)Yes AddressChar(100)No PhoneChar(12)NoFormat: ###-###- #### CUSTOMER
41
IST210 41 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks PurchaseID Price Date BookID EmailAddress PURCHASE
42
IST210 42 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks PurchaseIDintPrimary key YesSurrogate key: initial value = 1, increment = 1 PricefloatYes DateDateTimeYes BookIDintForeign key YesReference: BOOK EmailAddressChar(50)Foreign key YesReference: CUSTOMER PURCHASE
43
IST210 43 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EventID Name Date Type EVENT
44
IST210 44 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EventIDintPrimary key YesSurrogate key: initial value = 1, increment = 1 NameChar(50)Yes DateDateTimeNo TypeChar(20)No EVENT
45
IST210 45 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EmailAddress EventID CUSTOMER_EVENT
46
IST210 46 PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, EmailAddress) CUSTOMER(EmailAddress, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT(EmailAddress, EventID) Column NameData TypeKeyRequiredRemarks EmailAddressChar(50)Primary key, foreign key YesReference: CUSTOMER EventIDintPrimary key, foreign key YesReference: EVENT CUSTOMER_EVENT
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.