150 likes | 358 Vues
Entity-Relationship Model. Entity-Relationship Mode. What is it? Technique for developing an informal organization of tables How does it work? Identify entities (which become tables) Identify attributes of each entity (which become fields) Identify relationships. Notation. Entity
E N D
Entity-Relationship Mode • What is it? • Technique for developing an informal organization of tables • How does it work? • Identify entities (which become tables) • Identify attributes of each entity (which become fields) • Identify relationships
Notation • Entity • A general entity is a component of the database. • E.g., book, author, publisher, customer • Attribute • Property of an entity • E.g., title and price of a book; name, phone number of a publisher; name, address of a customer • Notation • An entity and its attributes • E.g., Books(ISBN, bkTitle, price)Authors (auID, auName, auPhone)Publishers (pubID, pubName, pubPhone)
Purpose of Attributes • Contain raw data for the database • E.g., bkTtitle, price in Books, auName in Authors • Identify one field whose values are unique; i.e., as a primary key. • E.g., auID in Authors, pubID in Publishers • Link a table to another table, i.e., as a foreign key. (Need not be included in the Entity-relationship diagram)
Entity-Relationship Diagram • Given the following entities: • Students (stdID, stdName, stdAddress) • Classes (clID, clName, clTime, clRoom, instructor) • Instructors (instID, instName, instGender) • How are they related?
Students, Classes, Instructors N Attends N Students Classes N Teaches 1 Instructors
Students with Attributes instName stdAddress clTime stdName stdEmail clName clRoom N Attends N Students Classes N Teaches
Refining Tables • Recall • Classes (clID, clName, clTime, clRoom, instName) • Several classes may have the same name. E.g. EN201-01, EN201-02 are both named “Intro to Writing.” • Rooms may require more information. • Instructor name is already in Instructor table
Create New Tables • Courses(crsID, crsName, crsCredits) • Rooms(rmID, rmLocation, rmNumber, rmCapacity) • Classes(clID, classTime, crsID, rmID, instID)Underlined and italicized fields are foreign keys.
More Tables Courses ? ? Taught as Holds Rooms ? ? ? Attends Classes Students N N N Teaches 1 Instructors
Your Turn • Bank database • What kind of entities are involved? • What are some of their attributes? • Academic database • What kind of entities are involved? • What are some of their attributes?
Your Turn (2) • Airline database • What kind of entities are involved? • What are some of their attributes? • Student Grades database • What kind of entities are involved? • What are some of their attributes?