2 Conceptual Level Data Model
2 Conceptual Level Data Model
Case Study (The case in here is only for teaching purpose and it is no way
related to any company)
Entity Sets
Entities are the principal data objects about which information is to be collected in E/R model.
Entities are usually recognizable concepts, either concrete or abstract, such as person, places,
things, or events which have relevance to the database. An entity set is then a set consisting of the
same type of entities that share same properties.
Consider the case study; some specific examples of entities are then:
EMPLOYEES, PROJECTS, CUSTOMERS …
The candidate entities from the requirement statements are the nouns and the adjective noun phrases.
The “EMPLOYEES” entity set represents all the set of employees and the “Projects” entity set
represents all the set of projects.
Attributes
Attributes are descriptive properties that are associated with an entity. A set of attributes describe
an entity.
A particular instance of an attribute is called a value.
For example, “Employee Id” and “Name” are the attributes of the “EMPLOYEES” entity set; and
“Kevin Jones” is one value of the attribute “Name”.
The domain of an attribute is the collection of all possible values an attribute can have. The domain
of “Name” is a character string.
Attributes can be classified as identifiers or descriptors.
Identifiers: more commonly called keys, uniquely identify an instance of an entity.
Example: “Employee Id” uniquely identifies an employee entity from the entity set.
Descriptor: describes a non-unique characteristic of an entity instance.
Example: “Name” is a descriptor for the “EMPLOYEES” entity set.
Other way of categorizing Attributes is as Simple and Composite attributes.
Simple Attributes: are attributes also known as Atomic Attributes that can not be divided
into subparts mainly of primitive types.
Example: “Age” and “Gender” of the “EMPLOYEES” entity set.
Composite Attributes: are attributes that are composed of smaller subparts that can be
subdivided into the subparts (Attributes).
Example: “Address” of the “EMPLOYEES” entity set that can be divided into “City”,
“Home Address”, “Phone”, and “P.O. Box”
Hierarchical Composite Attributes
Address
Another classification of attributes is based on the values that they can hold as: Single-valued and
Multi-valued attributes.
Single-valued Attributes: are attributes having only one possible value at any time.
Example: “Name” and “Gender” of the “EMPLOYEES” entity set.
Multi-valued Attributes: are attributes that are having possibly more than one value.
Example: “Address” of the “EMPLOYEES” entity set.
Relationship Sets
A Relationship represents an association between two or more entities. An example of a
relationship would be:
- “EMPLOYEES” are Assigned to “TEAMS”
- “CUSTOMERS” Owns “PROJECTS”
- “TEAMS” works on “PROJECTS”
A Relationship Set is then a set consisting same types of relationships. The entities involved in the
relationship are known as participating entities and the function the entity plays in a relationship
is called the entity’s role.
Example: In the Assigned relationship “EMPLOYEES” and “TEAMS” entity sets are the
participating entity sets; and the “EMPLOYEES” entity has a role as a “Programmer” or
“Team Leader” in the relationship.
Relationships are classified in terms of degree, connectivity, cardinality, and existence.
Degree: The degree of a relationship is the number of entities associated with the relationship. The
n-ary (multi-way) relationship is the general form for degree n. Special cases are the binary, and
ternary, where the degree is 2, and 3, respectively
Connectivity: The connectivity of a relationship describes the mapping of associated entity
instances in the relationship. The values of connectivity are “one” or “many”.
Cardinality: The cardinality of a relationship is the actual number of related occurrences for each of
the two entities. The basic types of connectivity for relations are: one-to-one, one-to-many, and many-
to-many.
A B A B A B
a1 b1 b1 a1 b1
a2
a2 b2 b2 a2 b2
a3 b3 b3 a3 b3
a4
a4 b4 b4 a4 b4
Existence: denotes whether the existence of an entity instance is dependent upon the existence of
another, related, entity instance. The existence of an entity in a relationship is defined as either
mandatory or optional.
Design Principles
E/R Diagram
The Entity Relationship (E/R) data model is a diagrammatical data model. The elements of the
E/R model are represented by:
- Rectangles - for the Entity sets,
- Ellipses - for the Attributes,
- Diamonds - for the Relationships, and
- Lines - for the links between the attributes and the entity sets and between the entity sets
and the relationships.
- Double border Rectangles - for the weak entity sets.
- Double border Ellipses - for the multi-valued attributes.
- Dashed border Ellipses - for the derived attributes.
- Arrow Head Line - for the link between an entity set and a one-to-one or many-to-one
relationship. The arrow is headed to the one side entity set.
Example
- “EMPLOYEES” are Assigned to “TEAMS”
- “CUSTOMERS” Owns “PROJECTS”
- “TEAMS” works on “PROJECTS”
Name Name
Descr EmpId BDate
Age
TEAMS Assigned EMPLOYEES
Address
Name
ProjId CustId Address
SDate DDate
Fig 3. Sample Partial E/R Model
Composite attributes are represented by linked ellipses as depicted in the above figure with the
attributes “Address” and “H Addrs”.
EiT-M (School of Electrical and Computer Engineering) 2- 5/17
ECEG-4172 - Database System Conceptual Level Data Model
Multi-way Relationship: Consider the three way relationship between the “PROJECTS”,
“TEAMS”, and “SOFTWARE” entity sets.
Cardinality Limits of a Relationship: The credential limit of a relationship is labeled as:
- 0..* or 0..∞ indicating zero or more participation of the entity in the relationship.
- 1..* or 1..∞ indicating one or more participation of the entity in the relationship.
- 0..1 indicating zero or one participation of the entity in the relationship.
- 1..1 indicating exactly one participation of the entity in the relationship.
Task
5..8
EMPLOYEES
Fig 5. Multi-way Relationships and credential limits
The multi-way (ternary) relationship shown in figure 5 above can be reduced to a binary
relationship with the use of an entity set in place of the relationship and having three new
relationships for the links in between the participating entity sets and the relationship.
Task
For
PROJECTS
Fig 6. Multi-way Relationships to Binary Relationship
If the multi-way relationship set that is transformed into the binary relationship had any attributes,
these are assigned to the entity set that replaces the relationship.
Entity Set Roles in a Relationship: In some relationships a single entity set may participate more
than once in such case a label is on the link line from the entity set is used to differentiate the
Assigned By
TEAMS Assigned EMPLOYEES
Assigned
For
Fig 7. Role of an entity set in a Relationship.
participation of the entity set.
Total Participation in a Relationship: The participation of the entity set in a relationship is said
to be in total if every element of the entity set is at least related to one element in the other
participating entities through the relationship; otherwise the participation is said to partial. A total
participation in E/R model is represented by a double line from the entity set to the relationship.
Consider the relationship between the “SOFTWARE” and “ASSIGNMENT” entity sets above.
Every Software is produced in an Assignment, hence the relationship from the “SOFTWARE” to
the “ASSIGNMENT” is total.
Task
Design Issues
The following are some useful principles to be followed in designing databases.
1. Faithfulness - first and for most, the design should be faithful to the specifications. That is
classes or entity sets and their attributes should reflect reality.
2. Avoiding Redundancy - be careful to say everything only once.
3. Simplicity - avoid introducing more elements into your design than are absolutely
necessary.
4. Picking the Right kind of Element - Sometimes we have options regarding the type of
design element used to represent a real-world concept.
Use of Entity Set versus Attributes: Generally, of something has more information associated
with it than just its name, it probably needs to be an entity set. However, if it has only its
name to contribute to the design, then it is probably better to make it an attribute.
Example: A “SOFTWARE” entity set may have a “Version” attribute, or “VERSION”
can be argued to be an entity set.
Entity versus Relationship Sets: Since relationships represent events there will always be
confusion between the entity sets and relations.
Binary versus n-ary Relationship Sets: Generally, of something has more information associated
with it than just its name, it probably needs to be an entity set. However, if it has only its
name to contribute to the design, then it is probably better to make it an attribute.
Remarks on Designing
- Choose meaningful naming for the entities, attributes and relationships.
- Use short links.
- Cluster diagram if it has too many entities and relationships.
Keys
As described above keys are attributes or set of attributes that suffice to distinguish entities from
each other.
A super key also know as super set is then a set of one or more attributes that in group
(collectively) can identify an entity uniquely from the entity set.
Example: Consider the “EMPLOYEES” entity set, then
- “EmpId”, “EmpId, Name”, “NationalId”, “NationalId, BDate”, … are super keys
- “Name”, “BDate” are NOT super keys
REMARK
If K is a super set (super key) then a set consisting of K is also a super set.
The more interesting super set is the minimal super set that is referred to as the candidate key.
The candidate key is the sufficient and the necessary set of attributes to distinguish an entity set.
Example: In the “EMPLOYEES” entity set
- “EmpId”, “NationalId”, “Name, BDate” (assuming that there is no coincidence that
employees with the same name may born on the same day) … are candidate keys
The designer of the database is the one that makes the choice of the candidate keys for
implementation, but the choice has to be made carefully. Primary key is a term used to refer to the
candidate key that is selected by the designer for implementation.
Name
ProjId CustId Address
SDate DDate
Example:
- Consider “TEAMS” entity set Teams with the same name can be formed to work on
different projects. Thus neither “Name” nor “Description” can uniquely identify a
“TEAMS” entity. Rather an entity will be distinguished when it is related to a
“PROJECT” entity. Note that the relationship in between is a many-to-one relationship
Name
ProjId Descr
SDate DDate
PROJECTS EMPLOYEES
ISA ISA
Aggregation
One deficiency in E/R modeling is the fact that a relationship is allowed only between entity sets.
But in some cases it may be advantageous to have a relationship between a relationship and an
entity set or a collection of entity sets.
Example:
- Consider the “WorksOn” relationship between “TEAMS” and “PROJECTS”. From the case
study it is to be noted that every project is to be lead by a senior manager. Hence the
manager is responsible for managing the teams, projects and the outcome of the project,
the software. Therefore the resulting E/R model would be as follows.
Manages
EMPLOYEES
Fig 12. Redundancy in E/R model
As can be seen from the diagram above redundancy loop is introduced as the E/R model doesn’t
allow a direct association of a relationship to a relationship.
An alternative way to avoid the redundancy is with the use of the aggregation. Aggregation is an
abstraction through which collection of related entity sets and relationships are treated as high-
level entities. It allows indicating for a relationship set (identified through a box) to participate in
another relationship set.
Example:
- The previous example can be alternatively represented as follows
Manages
EMPLOYEES
Fig 13. Aggregation in E/R model
class <name> {
<list of element declarations, separated by semicolons>
};
Attributes in ODL
Attributes are (usually) elements with a type that does not involve classes. They can be of simple,
enumerated or structured type. The syntaxes for the three types are as follows, respectively:
REMARK: The names for the enumerated and structured data types are not necessary for the
declaration but giving the name helps to refer to the type outside the class declaration
using the scoped name such as, “Employees::Gender” and “Employees::Address”.
Relationships in ODL
Syntax for a relationship in ODL is as follows
class Employee {
relationship Set <Team> assigned
inverse Team::formed;
};
class Team {
relationship Set <Employee> formed;
inverse Employee::assigned;
};
- Consider the one-to-many relationship between “PROJECTS” and “CUSTOMERS”
class Project {
relationship <Customer> ownedBy
inverse Customers::owns;
};
class Customer {
relationship Set <Project> owns;
inverse Projects::ownedBy;
};
class Project {
relationship <Software> produce
inverse Software::producedIn;
};
class Software {
relationship <Project> producedIn;
inverse Projects:: produce;
};
NOTE: Recall that ODL does not support 3-way or higher relationships. Multiway relationships in
ODL may be simulated by a “connecting” class, whose objects represent tuples of objects
that will be connected by the multiway relationship.
Inheritance in ODL
Inheritance in ODL is similar to the usual object-oriented inheritance principle. It indicates a
relationship between superclass and subclasses. Subclass lists only the properties unique to it and it
inherits its superclass’ properties.
Inheritance in ODL design is indicated by the colon operator as follows
class <Subclass>:<Superclass> {
<list of element declarations>
};
Example:
- Consider the “PART-TIME EMPLOYEES” class that is inherited from “EMPLOYEES”
class.
class PartTimeEmployee:Employee {
attribute real hourlPay;
attribute integer contractPeriod;
relationship Set <TimeSchedule> works
inverse TimeSchedule::working;
};
Example: