Understanding Relational Data Models
Understanding Relational Data Models
1
3/12/2020
Tables
Tuple:- A single row of a table, which contains a single record for
that relation is called a tuple.
Relation instance :- A finite set of tuples in the
relational database system represents relation instance
Relation schema:- A set of attributes is called a relation schema
Relation key:- They are used to establish and identify
relationships between tables and also to uniquely identify any
record or row of data inside a table. 3
Attribute domain: It is the set of values allowed in an attribute
Prepared by Shimi Biju
ENTITY-RELATIONSHIP MODEL
Entity-Relationship (ER) Model is based on the notion of real-
world entities and relationships among them. While formulating
real-world scenario into the database model, the ER Model creates
entity set, relationship set, general attributes and constraints.
ER Model is best used for the conceptual design of a database. ER
Model is based on −
Entities and their attributes.
Relationships among entities.
2
3/12/2020
ENTITY SET
An entity is a “thing” or “object” in the real world that is
distinguishable from all other objects. For example, each
person in an enterprise is an entity.
An entity has a set of properties, and the values for some set
of properties may uniquely identify an entity. For instance, a
person may have a person-id.
An entity set is a set of entities of the same type that share the
same properties, or attributes.
An entity is represented by a set of attributes. Attributes are
descriptive properties possessed by each member of an entity
set.
The designation of an attribute for an entity set expresses that
the database stores similar information concerning each entity
in the entity set;
5
ATTRIBUTES
For each attribute, there is a set of permitted values, called
the domain, or value set, of that attribute.
The domain of attribute course id might be the set of all text
strings of a certain length.
An attribute, as used in the E-R model, can be characterized
by the following attribute types. Entities are represented by
means of rectangles.
Rectangles are named with the entity set they represent.
Every ellipse represents one attribute and is directly
connected to its entity (rectangle).
3
3/12/2020
ATTRIBUTES (CONT.)
Simple and
Composite attributes
Single-valued and
multivalued
attributes
ATTRIBUTES (CONT.)
Derived Attribute
4
3/12/2020
CARDINALITY
In terms of data models, cardinality refers to the relationship between two
tables
Mapping cardinalities, or cardinality ratios, express the number of entities
to which another entity can be associated via a relationship set. Mapping
cardinalities are most useful in describing binary relationship sets, although
they can contribute to the description of relationship sets that involve more
than two entity sets.
10
5
3/12/2020
CARDINALITY (CONT)
Many to one. An entity in A is associated with at most one
entity in B. An entity in B, however, can be associated with
any number (zero or more) of entities in A.
11
12
6
3/12/2020
KEYS
Keys are very important part of Relational database. They are used to
establish and identify relation between tables. They also ensure that each
record within a table can be uniquely identified by combination of one or
more fields within a table.
Primary Key
A primary key is a candidate key that is most appropriate to be the main reference key for the
table. As its name suggests, it is the primary key of reference for the table and is used
throughout the database to help establish relationships with other tables. As with any
candidate key the primary key must contain unique values, must never be null and uniquely
identify each record in the table.
Customer Name First Name Last Name
1 Sally Thompson
2 Sally Henderson
3 Harry Henderson
4 Sandra Wellington 13
KEYS (CONT.)
Foreign Keys
Foreign key are columns that point to primary key columns.
Example, OrderNo is the primary key of the table ORDERS below and
CustomerNo is a foreign key that points to the primary key in the CUSTOMERS
table.
Order Employee Customer Supplier Price Item
No No No
1 1 42 Harrison $235 Desk
2 4 1 Ford $234 Chair
3 1 68 Harrison $415 Table
4 2 112 Ford $350 Lamp
5 3 42 Ford $234 Chair
6 2 112 Ford $350 Lamp
7 2 42 Harrison $235 Desk 14
7
3/12/2020
KEYS (CONT.)
The only true requirement of the column at which a foreign key
points is that it must contains unique values.
Referential integrity.
Null is not the same as a zero numeric value or a text string filled
with spaces; zeros and spaces are values, but a null represents the
absence of a value. Therefore, nulls should be treated differently 15
from other values.
Prepared by Shimi Biju
KEYS (CONT.)
Candidate Key
16
8
3/12/2020
KEYS (CONT.)
Super Key
17
KEYS (CONT.)
Alternative or Secondary Key
A table may have one or more choices for the primary key.
Those not selected are known as secondary keys or
alternative keys.
For example in the table showing candidate keys above we
identified two candidate keys, studentId and firstName +
lastName.
The studentId would be the most appropriate for a primary
key leaving the other candidate key as secondary or
alternative key.
It should be noted for the other key to be candidate keys,
we are assuming you will never have a person with the
same first and last name combination. As this is unlikely 18
we might consider fistName+lastName to be a suspect
candidate key Prepared by Shimi Biju
9
3/12/2020
Now record 3 and record 5 are not distinguishable as there Rollno is Null
and it is not possible to exactly locate one of the students as he is having
common name, class and marks with some other student. Record number 3
and 5 violates the rule of primary key because the Rollno is primary key,
all the value of attributes are unique but their primary key entries are
NULL and this violates the integrity rule 1, so these records are not
19
allowed in RDBMS.
REFERENTIAL INTEGRITY
Referential integrity is a property of data stating that all its references are
valid. In the context of relational databases, it requires that if a value of one
attribute of a relation references a value of another attribute, then the
referenced value must exist..
Consider the following database to understand the referential
integrity rule:
20
10
3/12/2020
E-R DIAGRAM
ER-Diagram is a visual representation of data that describes how data
is related to each other. E-R diagram can express the overall logical
structure of a database graphically. E-R diagrams are simple and
clear—qualities that may well account in large part for the
widespread use of the E-R model. Such a diagram consists of the
following major components:
In E-R Diagram, an entity is represented using rectangles. Consider
an example of an Organisation. Employee, Manager, Department,
Product and many more can be taken as entities from an Organisation.
21
Attribute
An Attribute describes a
property or characteristic of an
entity. For example, Name,
Age, Address etc can be
attributes of a Student. An
attribute is represented using
22
eclipse.
Prepared by Shimi Biju
11
3/12/2020
RELATIONSHIP
A relationship is an association among several entities. For example, we
can define a relationship that associates with entity.
We can define the relationship set takes to denote the association between a
student and the course sections in which that student is enrolled.
The association between entity sets is referred to as participation; that is,
the entity sets E1, E2,..., En participate in relationship set R.
A relationship instance in an E-R schema represents an association between
the named entities in the real-world enterprise that is being modeled.
24
12
3/12/2020
25
Specialization
27
Aggregration
Prepared by Shimi Biju
13
3/12/2020
GENERALIZATION
Generalization is a bottom-up approach in which two
lower level entities combine to form a higher level entity.
In generalization, the higher level entity can also
combine with other lower level entities to make further
higher level entity.
It's more like Superclass and Subclass system, but the
only difference is the approach, which is bottom-up.
Hence, entities are combined to form a more generalised
entity, in other words, sub-classes are combined to form
a super-class.
28
GENERALIZATION
14
3/12/2020
GENERALIZATION
SPECIALIZATION
31
15
3/12/2020
32
16
3/12/2020
AGGREGRATION
Aggregration is a process when relation between two
entities is treated as a single entity.
The relationship between Center and Course together, is acting as an Entity, which
is in relationship with another entity Visitor. Now in real world, if a Visitor or a 34
Student visits a Coaching Center, he/she will never enquire about the center only
or just about the course, rather he/she will ask enquire about both.
Prepared by Shimi Biju
AGGREGRATION
17
3/12/2020
CODD’S RULES
Dr Edgar F. Codd, after his extensive research on the
Relational Model of database systems, came up with
twelve rules of his own, which according to him, a
database must obey in order to be regarded as a true
relational database.
These rules can be applied on any database system that
manages stored data using only its relational capabilities.
This is a foundation rule, which acts as a base for all the
other rules.
36
37
18
3/12/2020
38
39
19
3/12/2020
40
41
20
3/12/2020
42
43
21
3/12/2020
44
45
22
3/12/2020
46
47
23
3/12/2020
48
INTEGRITY CONSTRAINTS
49
24
3/12/2020
50
1. DOMAIN CONSTRAINTS
51
25
3/12/2020
52
53
26
3/12/2020
54
4. KEY CONSTRAINTS
Keys are the entity set that is used to identify an entity within
its entity set uniquely.
An entity set can have multiple keys, but out of which one key
will be the primary key.
A primary key can contain a unique and null value in the
relational table.
Example:
55
27