Sei sulla pagina 1di 33

Objectives:

To illustrate how relationships between entities are defined and refined. To know how relationships are incorporated into the database design process. To describe how ERD components affect database design and implementation.

DEFINITION
Entity Relationship Diagram (ERD)
A detailed, logical representation of the entities, associations and data elements for an organization or business

Notation uses three main constructs :


Entities Relationships Attributes

Chen Model or Crows Foot Model

DIFFERENCES OF MODEL
Crows Foot Entity Chen

Department Department

Attribute

Department Staff No

Staff No.

Relationship
employs employs 3

Chen Notation

EntityName

Verb Phrase

AttributeName

Represents a set or collection of objects in the real world that share the same properties

named property or characteristic of an entity Association between the instances of one or more entity types

Person, place, object, event or concept about which data is to be maintained

ENTITY
An entity is a thing of interest to a system about which information is kept For example in a Hospital Administration System, some likely entities would include: Patient, Doctor, Operation, Ward Each of these things are of interest to the system and would have data stored about them

ENTITIES EXAMPLES
Examples of entities:
Person: EMPLOYEE, STUDENT, PATIENT Place: STORE, WAREHOUSE Object: MACHINE, PRODUCT, CAR Event: SALE,REGISTRATION, RENEWAL Concept: ACCOUNT, COURSE

Guidelines for naming and defining entity types:


An entity type name is a singular noun An entity type should be descriptive and specific An entity name should be concise Event entity types should be named for the result of the event, not the activity or process of the event.

CHOOSING ENTITIES
Example A sale always starts with a customer receiving an estimate. The estimate then becomes an order. An order can be for one or more stock items. Each stock item belongs to a certain stock category (e.g. taps, sinks, cupboards etc.)

ATTRIBUTE
An attribute is an item of data held about an entity In computer systems an attribute is a field of information

Example : Sales System


Entity : Customer Attributes : Customer Name, Customer Address, Customer Phone Number

Entity : STUDENT Attributes: Student_ID, Student_Name, Home_Address, Phone_Number, Major

Guidelines for naming attributes:


An attribute name is a noun.

An attribute name should be unique


To make an attribute name unique and clear, each attribute name should follow a standard format Similar attributes of different entity types should use similar but distinguishing names.

KEY S
A key attribute uniquely identifies a specific occurrence of an entity This may also be referred to as a primary key Examples of primary keys include:
ISBN Student Number Staff ID

10

10

EXAMPLE
In a Sales System, customer name and address are attributes of the entity customer.

The primary key is likely to be Customer Code or Customer ID as the unique identifier for each customer in the system.

11

11

Primary Key
StaffID

Name

Gender

IC

Staff

Entity
Staff
PK StaffID

Attributes
Name Gender IC

12

EXAMPLE : BABY SITTER SERVICE


The AITP Service Club wants to run a babysitting service. Customers call to request a sitter and the Club Coordinator assigns an employee to sit for the customer from a list of employees available for the particular day requested.

13

13

BABYSITTING SYSTEM
Data is used to:
Assign employee to job Determine availability

Data to be captured in database:


Employee data Job data Customer data

14

14

BABYSITTING SYSTEM
Employee

Attributes: EmpID, Name, Address, Phone Number, Available Hours, JobNo


Job

Attributes: JobNo, JobDate, JobTime, EmpID


Customer

Attributes: CusNo, Name, Address, Phone Number, JobNo

15

15

ERD - Babysitter Service

16

ERD - Babysitter Service


EMPLOYEE
1

CUSTOMER
M

assigned to

JOB

Related to

17

17

TO BE CONTINUED

18

FOREIGN KEY
Definition A foreign key is a relationship or link between two tables which ensures that the data stored in a database is consistent. Example: In the example, there is a link between the Company and Contact tables. The Company table is the parent table in the link. The Contact table is the child: the Company_ID field in the Contact table indicates which Company

a Contact belongs to.

19

Foreign Key Primary Key

20

RELATIONSHIPS
DEFINITION: Associations between instances of one or more entity types that is of interest
Relationship name: write

Author

write

Book

An author writes one or more books A book can be written by one or more authors.

21

DEGREE OF RELATIONSHIPS
Degree: number of entity types that participate in a relationship

Three cases
Unary: between two instances of one entity type Binary: between the instances of two entity types Ternary: among the instances of three entity types

22

CARDINALITY AND CONNECTIVITY


Relationships can be classified as either
one to one ( 1:1 ) one to many (1:M) many to many (M:N)

Connectivity

Cardinality : minimum and maximum number of instances of Entity B that can (or must be)

associated with each instance of Entity A.

23

2.4 CARDINALITY AND CONNECTIVITY

PROFESSOR

teaches

CLASS

A professor teaches class OR A class is taught by professor

How Many??

24

CARDINALITY AND CONNECTIVITY

Connectivity

1
PROFESSOR teaches

CLASS

(1,4) Cardinality

(1,1)

25

CONNECTIVITY
Chen Model
1 to represent one M to represent many

1 M

26

BINARY RELATIONSHIPS
1:M relationship Relational modeling ideal Should be the norm in any relational database design

The 1: M relationship between PAINTER and PAINTING 27

The Implemented 1:M relationship between PAINTER and PAINTING

BINARY RELATIONSHIPS

1:1 relationship Should be rare in any relational database design A single entity instance in one entity class is related to a single entity instance in another entity class Could indicate that two entities actually belong in the same table

29

The 1:1 Relationship Between PROFESSOR and DEPARTMENT

BINARY RELATIONSHIPS
M:N relationships Can be implemented by breaking it up to produce a set of 1:M relationships

31

The M:N Relationship Between STUDENT and CLASS Bowser Accounting 1 (ACCT-211) Intro to Microcomputing (CIS-220)

Smithson

Intro to Statistics (QM-261)

This CANNOT be implemented as shown next..

~The END~ Q&A

33

Potrebbero piacerti anche