Yorkville High School Computer Science Department
Yorkville High School Computer Science Department on Facebook  Yorkville High School Computer Science Department Twitter Feed  Yorkville High School Computer Science Department on Instagram

Yorkville High School Computer Science

ASSIGNMENTS: Build a Computer - September 25, 2018 :: Network App - December 14, 2018

Database Programming :: Lessons :: ER Diagrams

Entity-Relationship Model

A data model is a way of describing the structure of data. Two general types of data models include conceptual data models and logical data models. An Entity-Relationship Model is a type of conceptual data model and is independent of a DBMS so it can be applied to any system. Below is an example of an ER diagram following the Entity-Relationship Model.

ER Diagram
©CS Odessa LLC

An entity is an important object about which information is kept. An entity is a noun so it can be a person, place, thing, or event. In an ER diagram an entity is denoted with a rectangle with the singular name inside.

Student Entity
Created with Draw.io
Enrolled In Relationship
Created with Draw.io

A relationship is an associate among one or more entities and is typically a verb. It is represented as a diamond with the name inside and cannot exist without entities.

 

The degree of a relationship is the number of entities associated with a relationship. The degree can be binary (two entities), ternary (three entities), or n-ary (more than three entities).

 

Degree of a Relationship
Binary and Ternary Relationships: Created with Draw.io

The cardinality or a relationship is the constraint on the mapping of the connected entities. It can be written as (min, max) or indicated through lines. The minimum is zero or one (most common) and the maximum is one or many (most common).

A one-to-one relationship associates a single entity with another single entity. A one-to-one relationship is indicated with a line with two vertical lines at the entity end or the text (1, 1). The vertical line furthest from the entity can be changed to a circle for an optional relationship.

One-to-One Relationship
Created with Draw.io

A one-to-many relationship associates a single entity with at least one of another entity. The many part of a one-to-many relationship is indicated with three small branching lines at the end of the line at the entity end or the text (1, 1) on the one side and (1, m) on the many side.

One-to-Many Relationship
Created with Draw.io

A weak entity is an entity that cannot exist without another entity. It is indicated with a double-border around the relationship diamond and the entity that is dependent upon another entity.

Weak Entity
Created with Draw.io

An mandatory many-to-many can be indicated with (1, m) or with a many-to-many line with a vertical line before the three branching lines. An optional many-to-many can be indicated with (0, m) or a circle before the three branching lines.

Mandatory Many-to-Many Relationship
Created with Draw.io
Optional Many-to-Many Relationship
Created with Draw.io

An attribute is a characteristic of an entity or relationship. Sometimes an attribute is attached to an entity or relationship using a line and an oval, but many ER diagrams have a lot of entities so this can become crowded. In a crowded ER diagram attributes are not included. They are instead included in a second document called an attribute list.

In the diagram below, the Student ID attribute is underlined indicating it is a key, which will be defined later; name is a descriptive of the entity Students; majors is a multivalued descriptive that has more than one value; and address is a composite attribute that has its own attributes.

Student Attributes
Created with Draw.io

An attribute on a relationship can only be associated with a many-to-many relationship. In the relationship below you must know the Student and the Course to access the Grade attribute.

An Attribute on a Relationship
Created with Draw.io

Recursive Relationships

A Network Recursive Relationship
©Northern Illinois University

A recursive relationship occurs when an entity is related to itself. A many-to-many recursive relationship is known as a network. In the example below, a person can have many relatives (or no relatives).

A Network Recursive Relationship
Created with Draw.io
A Tree Recursive Relationship
©Northern Illinois University

A one-to-many recursive relationship is known as a tree. In the example below, a department reports to a single department. A department may have zero, one, or more departments reporting to it.

Tree Recursive Relationship
Created with Draw.io

Inheritance and Aggregation

Entities can have supertypes and subtypes just like classes in object-oriented programming languages like Java. A generalization subtype means an instance of the supertype cannot exist without being related to at least one instance of the subtype. The supertype is the union of the subtypes. In the example below, a person MUST be a Faculty, Student, or Staff.

Generalization Inheritance
Created with Draw.io

A specialization subtype specializes the supertype so an instance of the supertype can exist without being related to any subtype. In the example below, a person CAN be a Faculty, Student, or Staff, but doesn't have to be any of them.

Specialization Inheritance
Created with Draw.io

With overlapping subtype entities an instance of the supertype can be related to one or more of the subtypes. In the example below, a Person CAN be any combination of Faculty, Student, and Staff.

Overlapping Inheritance
Created with Draw.io

With disjoint subtype entities the supertype can only be an instance of ONE of the subtypes.

Disjoint Inheritance
Created with Draw.io
Inheritance Combinations
Created with Draw.io

Combinations let you combine the inheritance subtypes:

In the example to the right, a Person MUST be ONE and ONLY ONE of either Faculty, Staff, or Student.

 

An aggregation is an is-part-of relationship, or ispo relationship. In the example below, a Car is made up of one hood, four wheels, and two doors.

Aggregation
Created with Draw.io
Yorkville High School Computer Science Department on Facebook Yorkville High School Computer Science Department Twitter Feed Yorkville High School Computer Science Department on Instagram