entity-relationship model. entity-relationship mode what is it? what is it? –technique for...

14
Entity- Entity- Relationship Model Relationship Model

Upload: aubrey-lewis

Post on 03-Jan-2016

215 views

Category:

Documents


0 download

TRANSCRIPT

Entity-Relationship Entity-Relationship ModelModel

Entity-Relationship ModeEntity-Relationship Mode

What is it?What is it?– Technique for developing an informal Technique for developing an informal

organization of tablesorganization of tables How does it work?How does it work?

– Identify entities (which become tables)Identify entities (which become tables)– Identify attributes of each entity (which Identify attributes of each entity (which

become fields)become fields)– Identify relationshipsIdentify relationships

NotationNotation EntityEntity

– A general entity is a component of the database.A general entity is a component of the database.– E.g., book, E.g., book, authorauthor, , publisherpublisher, , customercustomer

AttributeAttribute– Property of an entityProperty of an entity– E.g., E.g., titletitle and and priceprice of a book; of a book; namename, , phone phone

numbernumber of a publisher; of a publisher; name, addressname, address of a of a customercustomer

NotationNotation– An entity and its attributesAn entity and its attributes– E.g., E.g.,

Books(ISBN, bkTitle, price)Books(ISBN, bkTitle, price)Authors (auID, auName, auPhone)Authors (auID, auName, auPhone)Publishers (pubID, pubName, pubPhone)Publishers (pubID, pubName, pubPhone)

Purpose of AttributesPurpose of Attributes Contain raw data for the databaseContain raw data for the database

– E.g., E.g., bkTtitlebkTtitle, , priceprice in Books, auName in in Books, auName in AuthorsAuthors

Identify one field whose values are Identify one field whose values are unique; i.e., as a primary key.unique; i.e., as a primary key.– E.g., E.g., auIDauID in Authors, in Authors, pubIDpubID in in

PublishersPublishers Link a table to another table, i.e., as Link a table to another table, i.e., as

a foreign key. (Need not be included a foreign key. (Need not be included in the Entity-relationship diagram)in the Entity-relationship diagram)

Entity-Relationship DiagramEntity-Relationship Diagram

Given the following entities:Given the following entities:– Students (stdID, stdName, stdAddress)Students (stdID, stdName, stdAddress)– Classes (clID, clName, clTime, clRoom, Classes (clID, clName, clTime, clRoom,

instructor)instructor)– Instructors (instID, instName, instGender)Instructors (instID, instName, instGender)

How are they related?How are they related?

Students, Classes, InstructorsStudents, Classes, Instructors

Students

Instructors

ClassesAttends

Teaches

N N

1

N

Students with AttributesStudents with Attributes

Students ClassesAttends

Teaches

N N

N

stdName

stdAddress clTime

clName clRoom

instName

stdEmail

Entity-Relationship DiagramEntity-Relationship Diagram

Entity-Relationship DiagramEntity-Relationship Diagram

Refining TablesRefining Tables

RecallRecall– Classes (clID, clName, clTime, clRoom,Classes (clID, clName, clTime, clRoom,

instName) instName) Several classes may have the same name. Several classes may have the same name.

E.g. EN201-01, EN201-02 are both named E.g. EN201-01, EN201-02 are both named “Intro to Writing.”“Intro to Writing.”

Rooms may require more information.Rooms may require more information. Instructor name is already in Instructor Instructor name is already in Instructor

tabletable

Create New TablesCreate New Tables

Courses(crsID, crsName, crsCredits)Courses(crsID, crsName, crsCredits) Rooms(rmID, rmLocation,Rooms(rmID, rmLocation,

rmNumber, rmCapacity) rmNumber, rmCapacity) Classes(clID, classTime, Classes(clID, classTime, crsIDcrsID, , rmIDrmID, ,

instID) instID)

Underlined and italicized fields are Underlined and italicized fields are foreign keys.foreign keys.

More TablesMore Tables

Students

Instructors

ClassesAttends

Teaches

N N

1

N

Rooms

Courses

Taught asHolds?

?

? ?

?

Your TurnYour Turn

BankBank database database– What kind of entities are involved?What kind of entities are involved?– What are some of their attributes?What are some of their attributes?

AcademicAcademic database database– What kind of entities are involved?What kind of entities are involved?– What are some of their attributes?What are some of their attributes?

Your Turn (2)Your Turn (2)

AirlineAirline database database– What kind of entities are involved?What kind of entities are involved?– What are some of their attributes?What are some of their attributes?

Student GradesStudent Grades database database– What kind of entities are involved?What kind of entities are involved?– What are some of their attributes?What are some of their attributes?