2. UNITTWO – DATA MODELLING: ENTITY
RELATIONSHIP DIAGRAM
•Relational Model
•Entity relationship diagram
3. RELATIONAL MODEL
• The relational data model was introduced by C. F. Codd in 1970.
Currently, it is the most widely used data model. The relational
model has provided the basis for:
• Research on the theory of data/relationship/constraint
• Numerous database design methodologies
• The standard database access language called Structured Query
Language (SQL)
• Almost all modern commercial database management systems
The relational data model describes the world as “a collection of
inter-related relations (or tables).
4. FUNDAMENTAL CONCEPT OF RELATIONAL
MODEL
• Relation
A relation, also known as a table or file, is a subset of the Cartesian
product of a list of domains characterized by a name. And within a
table, each row represents a group of related data values. A row, or
record, is also known as a tuple. The columns in a table is a field and
is also referred to as an attribute.
• Table
A database is composed of multiple tables and each table holds the
data.
6. FUNDAMENTAL CONCEPT OF RELATIONAL
MODEL cont.
• Column
A database stores pieces of information or facts in an organized
way. The principal storage units are called columns or fields or
attributes . These house the basic components of data into which
your content can be broken down.
• Records
Records contain fields that are related, such as a customer or an
employee. As noted earlier, a tuple is another term used for record.
7. FUNDAMENTAL CONCEPT OF RELATIONAL
MODEL cont.
• Properties of aTable
• A table has a name that is distinct from all other tables in the database.
•There are no duplicate rows; each row is distinct.
• Entries in columns are atomic. The table does not contain repeating
groups or multivalued attributes.
• Entries from columns are from the same domain based on their data type
including: number (numeric, integer, float, smallint,…) character (string)
date logical (true or false)
• Operations combining different data types are disallowed.
•Each attribute has a distinct name.
8. FUNDAMENTAL CONCEPT OF RELATIONAL
MODEL cont.
• Degree
The degree is the number of attributes in a table.
• Domain
Domain is a set of acceptable values that a column is allowed to contain. This
is based on various properties and the data type for the column.
For example:
• The domain of Marital Status has a set of possibilities: Married, Single,
Divorced.
•The domain of Shift has the set of all possible days: {Mon,Tue,Wed…}.
•The domain of Salary is the set of all integer greater than 0 and less than 244.
This simple means, the Marital status column will not accept the “attached” as
data since it is not part of the acceptable data set.
9. ENTITY RELATIONAL MODEL
• The entity relationship (ER) data model has existed for over 35
years. It is well suited to data modelling for use with databases
because it is fairly abstract and is easy to discuss and explain. ER
models are readily translated to relations. ER models, also called
an ER schema, are represented by ER diagrams. ER modelling is
based on three concepts:
• Entity
• Attribute
• Relationship
10. ENTITY, ENTITYTYPE AND ENTITY SET
•An entity is an object in the real world with an
independent existence that can be differentiated from
other objects. An entity might be:
•An object with physical existence (e.g., a lecturer, a
student, a car)
•An object with conceptual existence (e.g., a course, a job,
a position)
12. ENTITY, ENTITYTYPE AND ENTITY SET cont.
•EntityType
The entity type is a collection of the entity with similar
attributes. In the student table for example, we have each
row as an entity and they all have common attributes.
13. ENTITY, ENTITYTYPE AND ENTITY SET cont.
Student
E-R representation of Student entity type.
NB: We use rectangle to represent an entity type on E-R diagram
14. ENTITY, ENTITYTYPE AND ENTITY SET cont.
• Types of Entity type
1.Strong entity type
2.Weak entity type
Strong entity type (s) are entity types with key attribute.The
primary key helps in identifying the strong entity type.
Weak entity type(s) cannot be identified separately.They depend
on other strong entity for their identity.
17. ENTITY, ENTITYTYPE AND ENTITY SET cont.
•Entity set
Entity set is a collection of entities of the same entity type
at a any point in time.
18. ENTITY, ENTITYTYPE AND ENTITY SET cont.
• Existence dependency
An entity’s existence is dependent on the existence of the related
entity. It is existence-dependent if it has a mandatory foreign key
(i.e., a foreign key attribute that cannot be null). For example, in a
COMPANY database, a Spouse entity is existence -dependent on
the Employee entity.
Existence dependency
19. INDEPENDENT AND DEPENDENT ENTITIES
• Independent entity does not rely on another entity for
identification.
• Dependent entity relies on another entity for identification.
Independent entity Dependent entity
20. ATTRIBUTES
• Each entity is described by a set of attributes (e.g., Employee = (Name,
Address, Birthdate (Age), Salary). Each attribute has a name, and is
associated with an entity. In an entity relationship diagram, attribute is
represented by an oval with a name inside.
Name
Attribute represented on E-R diagram
21. TYPES OF ATTRIBUTES
• Simple attributes
Simple attributes are those drawn from the atomic value domains; they are
also called single-valued attributes. In the STUDENT database, an example of
this would be: Age = {23}.
22. TYPES OF ATTRIBUTES
• Composite attributes
Composite attributes can be divided into subparts. Using our
database example, Address may consist of Number, Street and
Suburb; Name = Firstname and Lastname.
Student
Name
Address
Birthdate
Number
Street
Suburb
Firstname
Lastname
23. salary
TYPES OF ATTRIBUTES
• Multivalued attributes
Multivalued attributes are attributes that have a set of values for each entity.
An example of a multivalued attribute from the Employee table below, are the
degrees of an employee: BSc, MIT, PhD. It is important to note that, to
represent multivalued attributes on relational schema, new tables are created.
Employee
Name
Address
salary
Degrees
Degrees
NB: Double ovals are used to represent Multivalued attributes on
E-R diagram
24. • Derived attributes
Derived attributes are attributes that contain values calculated from other
attributes. An example of this can be seen the E-R diagram below. Age can be
derived from the attribute Birthdate. In this situation, Birthdate is called a
stored attribute, which is physically saved to the database.
TYPES OF ATTRIBUTES
Employee
Name
Address
Birthdate
Age
Age
NB:Dotted oval with name inside represent derived
attributes on E-R diagram
25. •A key is an attribute or a set of attributes in a relation
that identifies a tuple (record) in a relation.
•Keys are defined in a table to allow access or storage of
data quickly.
•They are also used to create relationship between tables.
KEYS
27. •Primary key (PK): It helps to identify
every record present in a table uniquely.
There can be only one primary key in a
table. Every value of a primary key must
different with no repetition. No two row
can have the same primary key.The
primary Key field cannot be null. A null value is either
unknown or not application. It does not mean blank.
TYPES OF KEYS
28. •Candidate keys : Keys with attributes
that can uniquely identify rows of a table
are called candidate keys.There can be
more than two candidate keys from a table
but they can not be empty or null.The
primary is selected from the candidate keys.
TYPES OF KEYS
29. •Alternate keys : As stated, a table can
have multiple choice of a primary key,
however, it can choose only one. So, all
the keys which did not become the primary
key are called alternate keys.
TYPES OF KEYS
30. •Super key : It is set of attributes that
uniquely identifies each tuple of a relation.
Super key is the superset of a candidate
Key.The primary key of a table is picked
from super key set.
TYPES OF KEYS
31. •Composite key : If a table not have a
single attribute that qualifies for a
Candidate key, then you have to select
two or more columns to make a row
Unique. So, EmployeeName+Date of
Birth are used as primary key.
TYPES OF KEYS
32. •Foreign key : It is column of a table that points to the
primary key of another table. A foreign key is used to link
to tables. It helps to maintain data and referential
integrity.The DeptID on employee table is a foreign key.
TYPES OF KEYS
33. •Unique key :It is same as primary with
the difference being the existence of null.
Unique key field allows one value as
NULL value.
TYPES OF KEYS
34. It is the association between entities or tables. We will
discuss only six relationships in relational model:
•One to one relationship (1:1)
•One to many or many to one relationship (1:M)
•Many to many relationship (M:N)
•Unary relationship (Recursive)
•Binary relationship
•Ternary relationship
NB: Diamond symbol is used to represent relationship in
an E-R diagram.
RELATIONSHIPS
Works
35. •One to One relationship (1:1): It is used to create a
relationship between two tables in which single row of
the first table can only be related to one and only one
record of the second table.
TYPES OF RELATIONSHIPS
37. •One to Many relationship (1:M): It is used to create a
relationship between two tables. Any single row of the
first table can be related to one or more rows of the
second table. Meanwhile, the rows of the second table
can relate to only one row in the first table.
TYPES OF RELATIONSHIPS
39. •Many to Many relationship (M:N): In M:N relationship,
each record in the first table can relate to more than one
record in the second table. Likewise, a record in the
second table can relate more than one record in the first
table.
TYPES OF RELATIONSHIPS
40. TYPES OF RELATIONSHIPS
• Unary relationship: It describes a relationship in which a table is
in relationship with itself. One example is an employee database
that keeps track of which employee supervises other employees.
42. TYPES OF RELATIONSHIPS
• Ternary relationship: It describes an association among three
entities.This type of relationship is required when binary
relationship is not sufficient to describe the relationshipl