Entity Relationship Diagrams. Entities An entity is something about which the system/business needs...

15
Entity Relationship Diagrams

Transcript of Entity Relationship Diagrams. Entities An entity is something about which the system/business needs...

Page 1: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Entity Relationship Diagrams

Page 2: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Entities

• An entity is something about which the system/business needs to store data.

• Entities are drawn as rectangles

• The rectangle represents all instances of the named entity

• Important to distinguish between an entity and its instances

Page 3: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Attributes

• Entity is something about which we want to store data

• Specific items of data we want to store are data attributes

• To record attributes of the entity we list them within the entity shape

Page 4: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Example

Student

.Last name

.First name

Address

.Street address

.Town

.County

.Post code

Page 5: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Relationships

• Entities and attributes do not occur in isolation.

• The things they represent interact with and impact one another to support the business

• A relationship is a natural business association that exists between one or more entities

Page 6: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Example

• A current STUDENT is ENROLLED ON one or more SUBJECTS

• A SUBJECT is STUDIED BY none (zero), one or more students

STUDENTSUBJECT

Is enrolled on

Is studied by

Verb phrases are used for relationships

Page 7: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

The previous example shows the complexity or degree of each relationship

• Must there exist an instance of STUDENT for each instance of SUBJECT – No

• Must there exist an instance of SUBJECT for each instance of STUDENT – Yes

• How many instances of STUDY can exist for each instance of STUDENT – Many

• How many instances of STUDENT can exist for each instance of STUDY - Many

Page 8: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality continued

• Cardinality defines the minimum and maximum number of occurrences of one entity that may be related to a single occurrence of the other entity

• All relationships are bidirectional therefore cardinality must be defined in both directions for every relationship

Page 9: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality symbols

• Cardinality interpretation

Exactly one (one and only one)

Minimum instances 1

Maximum instances 1

or

Page 10: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

• Cardinality interpretation

Zero or one

Minimum instances 0

Maximum instances 1

Page 11: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

• Cardinality interpretation

One or more

Minimum instances 1

Maximum instances many (>1)

Page 12: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

• Cardinality interpretation

Zero, one or more

Minimum instances 0

Maximum instances many (>1)

Page 13: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

• Cardinality interpretation

More than one

Minimum instances >1

Maximum instances >1

Page 14: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

Cardinality tells us the following rules about the data we want to store:

• When we insert a STUDENT instance in the database we must link that student to at least one instance of SUBJECT

• A STUDENT can study more than one SUBJECT and we must be able to store data that includes all SUBJECT(s) for a given STUDENT

Page 15: Entity Relationship Diagrams. Entities An entity is something about which the system/business needs to store data. Entities are drawn as rectangles The.

Cardinality

• We must insert a SUBJECT before we can link (associate) STUDENTS to that SUBJECT. This is why SUBJECT can have zero students – no students have yet enrolled on that subject.

• Once a SUBJECT has been inserted into the database, we can link (associate) many STUDENTS with that SUBJECT