Vous êtes sur la page 1sur 23

Entity-Relationship Diagrams

Steps in producing an E-R Diagram (ERD) Identify the Entities. Identify the relationships. Consider 1-to-1 relationships. Deal with M-to-N relationships. Check for dependent existence. Draw the diagram. Check for Connection Traps. Redo the Entities table if necessary.

ACE2141-3 Tony Cornah 2006/07

Entities
Three rules. Each entity must have a key uniquely identifying it. The number of values for an attribute must be the same for all instances of an entity. Any relationship between entities must be 1-to-N. Identify the Entities. Summarise the information from system descriptions and the Data Flow Diagram. Identify the things described by this data. Check that the entities satisfy the first two of the Three Rules.

ACE2141-3 Tony Cornah 2006/07

Member of Staff Staff ID Name Address Timetabled Class Day Time Location CourseCode StaffID

Course CourseCode Title Summary (Day, Time, Location, StaffID) (Weds, 17:15, G29, A123) (Mon, 17:15, G29, B456) (Thurs, 19:15, G38, B456)
ACE2141-3 Tony Cornah 2006/07 3

Identify the Entities in the following description:


When a customer telephones the hotel, Chris, the receptionist, checks the booking log for an available room, which he offers to the customer, along with the price. If the customers is happy with that room, Chris fills in a duplicate booking form with the customers name, address and telephone number, and the dates, room number, room occupancy and price of the booking. He then updates the booking log by writing the customers name against the appropriate dates for the booked room. At various convenient points during the day, the receptionist sends all the original booking forms filled in so far to the customers as confirmation. He then files the duplicates in the booking form file.
ACE2141-3 Tony Cornah 2006/07 4

Relationships
Identify the relationships. Identify pairs of entities which have a connection. Check that the relationships satisfy the third of the Three Rules. Can one A have (more than) one B? Can one B have only one A? Consider 1-to-1 relationships. Either: Incorporate one entity into the other. Or: Keep them separate. Deal with M-to-N relationships. Create a new entity. Create two new 1-to-N relationships.
ACE2141-3 Tony Cornah 2006/07 5

Relationships are a Staff Member teaches a Class (taught by) a Class belongs to a Course (has) Can a Staff Member teach more than one Class? Can a Class be taught by only one Staff Member? Can a Class belong to (more than) one Course? Can a Course have only one Class? Can a Course have more than one Class? Can a Class belong to only one Course? Yes Yes No No Yes Yes

ACE2141-3 Tony Cornah 2006/07

Member of Staff

Course

Timetabled Class

ACE2141-3 Tony Cornah 2006/07

Now consider some modifications some Classes have (has) a Practical Session some Classes are taught by more than one Staff Member Can a Class have (more than) one Practical Session? Can a Practical Session be for by only one Class? Can a Staff Member teach more than one Class? Can a Class be taught by only one Staff Member? Can a Class be taught by only one Staff Member? Can a Staff Member teach more than one Class? Yes Yes Yes No No Yes

ACE2141-3 Tony Cornah 2006/07

Member of Staff

Course

Teacher For Timetabled Class

Practical session (only 1 per class)

ACE2141-3 Tony Cornah 2006/07

Check for dependent existence. Can A exist without a corresponding B? Can B exist without a corresponding A? Can a Staff Member exist without teaching? Can a Course exist without timetabled classes? Can a timetable slot exist without a Staff Member to teach and/or belonging to a Course? Yes No No

ACE2141-3 Tony Cornah 2006/07

10

Draw the diagram. Entities as named boxes. Relationships as arrows from the 1 to the N. Absolute (i.e. not dependent) existence as dotted half line. Describe each end of the relationship.

ACE2141-3 Tony Cornah 2006/07

11

Member of Staff
Teaches

Course
Has

Taught By

Belongs To

Timetabled Class

ACE2141-3 Tony Cornah 2006/07

12

Check for Connection Traps. University Site


Contains Is In Resident of Holds Details Of Registered At Lives In

Hall of Residence

Student

If these were the relationships identified then there would be no way of discovering where a student lived. If students could live in any hall (or in private accommodation):

If students must live in a hall on their site:

ACE2141-3 Tony Cornah 2006/07

13

Other Entity-Relationship Diagram notations:


http://members.iinet.net.au/~lonsdale/docs/erd.pdf http://ace2141.group.shef.ac.uk/SupplementaryMaterial/erd.pdf http://www.smartdraw.com/examples/view/index.aspx?catID=.Examples. SmartDraw.Software_Design.Entity_Relationship_Diagrm_-_ERD

The future UML Class Diagrams:


(Unified Modelling Language)
http://www.agilemodeling.com/artifacts/classDiagram.htm

Produce an Entity-Relationship Diagram for the Hotel Booking System


ACE2141-3 Tony Cornah 2006/07 14

ROOM
Is Reserved By Appears In

CUSTOMER
Makes Reserves Is For Appears In Refers To Contains Made Up Of Consists Of

BOOKING

LOG ENTRY

there are redundant relationships here


ACE2141-3 Tony Cornah 2006/07 15

Creating a database in Access


Open Access New Blank Database Specify values for Save in: File name: Create

choose directory type file name

ACE2141-3 Tony Cornah 2006/07

16

Creating a table using a Wizard


Tables tab Double click Create table by using wizard Select required Sample Table Customers Choose required Sample Field and select with " Can Rename Field if required Next to choose Primary Key and a new name for the table if required Can Modify the Table Design if required then Finish If design is modified, Close the design view and click Yes when asked if you want to Save the changes to the table

ACE2141-3 Tony Cornah 2006/07

17

Creating a table without a Wizard


Tables tab Double click on Create table in Design view Fill in Field Name: Booking Date Select Data Type: Date/Time Etc. References to other tables must match in type but Use Number to refer to AutoNumber fields Select the table key select the row(s) containing the key item(s) KEY icon or Edit - Primary Key Close the design view and click Yes when asked if you want to Save the changes to the table and name it

ACE2141-3 Tony Cornah 2006/07

18

Redo the Entities table if necessary. Consider these tables 1) for composite foreign keys 2) with the previous entityrelationship diagram

ACE2141-3 Tony Cornah 2006/07

19

ACE2141-3 Tony Cornah 2006/07

20

Creating relationships
Open the existing database and select Relationships (Right click and Show Table), Add all the tables and Close For each relationship Drag the attribute from the One side to the N side Select Enforce Referential Integrity Click Create Close, saving the changes to, Relationships

ACE2141-3 Tony Cornah 2006/07

21

ACE2141-3 Tony Cornah 2006/07

22

ACE2141-3 Tony Cornah 2006/07

23

Vous aimerez peut-être aussi