DATABASE DESIGN II IST 210: Organization of Data IST210 1
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
Previously: Exercise 3 IST210 3 Transform this diagram into tables STUDENT(StudentID, StudentName, ) COURSE(CourseID, CourseName, Instructor) REGISTRATION(StudentID, CourseID)
IST210 4 STUDENT(StudentID, StudentName, ) 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 Column Name Data Type KeyRequiredRemarks StudentID CourseID REGISTRATION table In-class Exercise 3
IST210 5 STUDENT(StudentID, StudentName, ) 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 Char(50)No Column Name Data Type KeyRequiredRemarks StudentIDintPrimary key, foreign keyYesReference: STUDENT CourseIDChar(20)Primary key, foreign keyYesReference: COURSE REGISTRATION table
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 Char(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”.
COURSE REGISTRATION SYSTEM Case study IST210 7
8 StudentID Name STUDENT StudentID CourseID Grade GRADE DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE Complete E-R Diagram
IST210 9 StudentID Name STUDENT DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE
IST STUDENT(StudentID, Name, , 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 STUDENT DepartName Building Phone DEPARTMENT CourseID CourseName Instructor COURSE
IST StudentID Name STUDENT StudentID CourseID Grade GRADE CourseID CourseName Instructor COURSE STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName)
IST STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade) StudentID Name STUDENT StudentID CourseID Grade GRADE CourseID CourseName Instructor COURSE
IST STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST STUDENT(StudentID, Name, , 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.
IST 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, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST Column Name Data Type KeyRequire d Remarks StudentID Name DepartName STUDENT STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST Column Name Data Type KeyRequire d Remarks StudentIDintPrimary key yesSurrogate key: initial value = 1, increment = 1 NameChar(100)yes Char(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, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST Column Name Data Type KeyRequire d Remarks CourseID CourseName Instructor DepartName COURSE STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST 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, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST Column Name Data Type KeyRequiredRemarks StudentID CourseID Grade GRADE STUDENT(StudentID, Name, , DepartName) DEPARTMENT(DepartName, Building, Phone) COURSE(CourseID, CourseName, Instructor, DepartName) GRADE(StudentID, CourseID, Grade)
IST STUDENT(StudentID, Name, , 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
LISA’S BOOKSTORE Case study IST210 22
IST BookID Title Year BOOK PurchaseID Price Date PURCHASE AuthorID Name Country PublisherName Location Phone AUTHOR PUBLISHER Address Name Address Phone CUSTOMER EventID Name Date Type EVENT Complete E-R Diagram
IST BookID Title Year BOOK AuthorID Name Country PublisherName Location Phone AUTHOR PUBLISHER
IST 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
IST BookID Title Year BOOK PurchaseID Price Date PURCHASE Address Name Address Phone CUSTOMER PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID)
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) BookID Title Year BOOK PurchaseID Price Date PURCHASE Address Name Address Phone CUSTOMER
IST Address 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, Address) CUSTOMER( Address, Name, Address, Phone)
IST Address 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, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID)
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) E-R diagram is transformed into a database with 8 tables
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequire d Remarks PublisherName Location Phone PUBLISHER
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks PublisherNameChar(50)Primary keyYes LocationChar(100)No PhoneChar(12)NoFormat: ###-###- #### PUBLISHER
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks BookID Title Year PublisherName BOOK
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, 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
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks AuthorID Name Country AUTHOR
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks AuthorIDintPrimary key YesSurrogate key, initial value = 1, increment =1 NameChar(100)Yes CountryChar(20)No AUTHOR
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks BookID AuthorID BOOK_AUTHOR
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks BookIDintPrimary key, foreign key YesReference: BOOK AuthorIDintPrimary key, foreign key YesReference: AUTHOR BOOK_AUTHOR
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks Address Name Address Phone CUSTOMER
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks AddressChar(50)Primary key Yes NameChar(50)Yes AddressChar(100)No PhoneChar(12)NoFormat: ###-###- #### CUSTOMER
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks PurchaseID Price Date BookID Address PURCHASE
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks PurchaseIDintPrimary key YesSurrogate key: initial value = 1, increment = 1 PricefloatYes DateDateTimeYes BookIDintForeign key YesReference: BOOK AddressChar(50)Foreign key YesReference: CUSTOMER PURCHASE
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks EventID Name Date Type EVENT
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks EventIDintPrimary key YesSurrogate key: initial value = 1, increment = 1 NameChar(50)Yes DateDateTimeNo TypeChar(20)No EVENT
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks Address EventID CUSTOMER_EVENT
IST PUBLISHER(PublisherName, Location, Phone) BOOK(BookID, Title, Year, PublisherName) AUTHOR(AuthorID, Name, Country) BOOK_AUTHOR(BookID, AuthorID) PURCHASE(PurchaseID, Price, Date, BookID, Address) CUSTOMER( Address, Name, Address, Phone) EVENT(EventID, Name, Date, Type) CUSTOMER_EVENT( Address, EventID) Column NameData TypeKeyRequiredRemarks AddressChar(50)Primary key, foreign key YesReference: CUSTOMER EventIDintPrimary key, foreign key YesReference: EVENT CUSTOMER_EVENT