2. What is Relational Model?
Relational model is most widely used data model for
commercial data-processing. The reason it’s used so
much is, because it’s simple and easy to maintain.
The model is based on a collection of tables. Users of the
database can create tables, insert new tables or modify
existing tables. There are several languages for database
programming.
SQL, Oracle, etc.
3. 3
The relational model invented by Edgar
F. Codd, of IBM's San Jose Research
Laboratory.
He suggested that the rigid
principles of mathematics could be
used to design, create and manage
a database system.
Codd's ideas were first published in
1970 in a seminal paper 'A
Relational Model of Data for Large
Shared Data Banks’.
This research gave birth to
the relational model on
which relational databases are
Brief History
3
Edgar F. Codd
4. 4
One of the rules proposed by Codd was that a
relational database should include a common
language that is used to:
create the database
store and manipulate the data within it
manage security.
The language that was widely adopted
was Structured Query Language (SQL)
Brief History
4
5. 5
Database Structure (Relational Model)
This model organizes data into one or
more tables (or "relations") of columns and
rows, with a unique key identifying each
row.
Generally, each table/relation represents
one "entity type"
(such as customer or product).
The rows represent instances of
that type of entity (such as "Lee“
or "chair") and the columns
representing values attributed to that
Database Structure
5
Relational Database
6. 6
Database Structure (Relational)
Data is organized into rows, columns and tables,
and it is indexed to make it easier to find relevant
information.
Database Structure
6
7. Relational Model Basic
The relational model gives us a single way to represent
data: as a two-dimensional table called a relation.
Attributes
Schemas
Tuples
Domains
Equivalent Representations of a Relation
8. Relational Model
Sets
collections of items of the same type
no order
no duplicates
Mappings
domain range
1:many
many:1
1:1
many:many
9. Attributes
Attribute
Title Year Length
Star Wars 1977 124
Might Ducks 1991 104
Wayne’s World 1992 95
Attributes of a relation serve as names for the columns of the
relation. Usually, an attribute describes the meaning of entries in
the column below.
Table = relation.
Column headers = attributes.
10. Schemas
The name of a relation and the set of attributes for a relation is
called a schema.
We show the schema for the relation with the relation name
followed by a parenthesized list of its attributes.
Relation schema = name(attributes) + other structure info.,
e.g., keys, other constraints.
Order of attributes is arbitrary, but in practice we need to
assume the (standard) order given in the relation schema.
Relational database schema = collection of relation schemas.
So the schema for previous slide is
Movies (title, year, length)
11. Tuples
Tuple
Title Year Length
Star Wars 1977 124
Might
Ducks
1991 104
Wayne’s
World
1992 95
The rows of a relation, other than the header row containin
The attribute names are called tuples.
A tuple has one component for each attribute of the relatio
12. Domains
Each attribute of a relation is associated with a
particular element type called domain.
The components of any tuple of the relation must have,
in each component, a value that belongs to the domain
of the corresponding column.
Example:
with title string is associated
with year integer is associated
15. Overview of Entity/Relationship
(E/R) Model
Entities
Relationships
Roles of entities in a
relationship
Constraints on entities:
domain constraints
key constraints
Constraints on relationships
Cardinality Constraints
(mapping constraints in SKS)
Participation Constraints
(existence dependencies in
SKS)
Weak Entity Sets
Multiway relationships
Subclass/superclass
Relationships
15
The Entity Relationship Data Model
16. Entities represent classes of real-world objects.
Person, Students, Projects, Courses are entities
of a University database
Relationships represent interactions between two
or more entities
Person
Is_Born_In
City
Lives_In
N 1
N 1
Entities & Relationship
16
The Entity Relationship Data Model
18. Entities are represented by means of rectangles.
Rectangles are named with the entity set they
represent.
Entities
ER Diagram Representation
18
The Entity Relationship Data Model
19. For Example:
Every employee works in at least one project
Every project has employees working on it.
EMPLOYEE
SSN
Name
Salary
PROJECT
Name
Code
WORKS_ON
N
N
Entities & Relationship
19
The Entity Relationship Data Model
21. Attributes represent elementary properties of the
entities or relationships. The stored data will be
kept as values of the attributes
PERSON
Ssn
Name
Profession
Is_Born_In
CITY
Name
Country
Elevation
Population
Lives_In
N 1
N 1
Birth_Date
Moving_Date
Attributes
21
The Entity Relationship Data Model
22. Attributes
single-valued vs multi-valued:
color of car could be multi-valued
salary of employee is single-
valued
atomic vs composite:
age of a person is atomic
address of a person could be
composite
stored vs derived:
derived attributes are those that
can be derived from other
attributes or entities, e.g., age
can be derived from date of birth.
The Entity Relationship Data Model
23. Attributes are properties of entities. Attributes are
represented by means of eclipses. Every eclipse represents
one attribute and is directly connected to its entity
(rectangle).
Attributes
ER Diagram Representation
23
The Entity Relationship Data Model
24. If the attributes are composite, they are further divided in a tree
like structure. Every node is then connected to its attribute. That
is composite attributes are represented by eclipses that are
connected with an eclipse.
Composite Attributes
ER Diagram Representation
24
The Entity Relationship Data Model
26. A classification could be disjoint or
overlapping
An entity could have more than one
classification
MAN
Draft_Status
FEMALE
Maiden_Name
PERSON
Ssn
Name
Address
SEX
Full_Time
Annual_Salary
Department
Part_Time
Hour_Rate
Weekly_Hours
JOB
Generalizations
Attributes
Attributes
26
The Entity Relationship Data Model
29. How entities act upon each other or are associated with each
other.
Think of relationships as verbs.
Relationship
For example, the named student
might register for a course.
The two entities would be the student
and the course, and the relationship
depicted is the act of enrolling,
connecting the two entities in that
way. Relationships are typically
shown as diamonds or labels directly
Entities
Attributes
Relationships between entities
Entities
Student
Name
Enroll
Course
The Entity Relationship Data Model
30. A relationship may involve more than two
entities
Course Meets Classroom
Day
Relationship
30
The Entity Relationship Data Model
32. Roles in a Relationship
The function that an entity plays in a relationship
is called its role
Roles are normally not explicitly specified unless
the meaning of the relationship needs
clarification
Roles needed when entity set is related to itself
via a relationship.
employee works for
manager
worker
32
The Entity Relationship Data Model
33. Example: Department Store 1/2
A department store operates in several cities
In a city there is one headquarter coordinating the local
operations
A city may have several stores
Stores hold any amount of items
Customers place their orders for any number of items to
a given store
GOAL: Optimize shopping in each city
33
The Entity Relationship Data Model
34. Example: Department Store 2/2
A department store
operates in several
cities
In a city there is one
headquarter
coordinating the local
operations
A city may have several
stores
Stores hold any amount
of items
Customers place their
orders for any number
of items to a given store
CITIES
City Name
State
HeadQtr Address
STORES
Store ID
Address
Manager ID
LOCATED
IN
ITEMS
Item ID
Description
Size
Color
ORDERS
Order Number
Order Date
ITEMS ORDERED
Qty Ordered
HOLD
Qty Held
IN-CITIES
Qty_in_cities
CUSTOMER
Customer Name
Address
Phone Number
PLACE
N
N
1
N
N N
N N N
1
34
The Entity Relationship Data Model
35. Phases of Database
Design Example
35
Conceptual
Design
Purchase
Product Person
Person
Country President
37. Constraints in E/R Diagrams
Finding constraints is part of the modeling process.
Commonly used constraints:
• Keys: social security number uniquely identifies a person.
• Single-value constraints: a person can have only one father.
• Referential integrity constraints: if you work for a company, it
must exist in the database.
• Other constraints: peoples’ ages are between 0 and 150. 37
The Entity Relationship Data Model
38. Keys in E/R Diagrams
address name ssn
Person
Product
name category
price
Underline to specify
keys in E/R diagrams
38
The Entity Relationship Data Model
42. Other Constraints
42
The Entity Relationship Data Model
Enterprise Constraints
Enterprise constraints – sometimes referred to as semantic
constraints – are additional rules specified by users or database
administrators and can be based on multiple tables.
Here are some examples.
•A class can have a maximum of 30 students.
•A teacher can teach a maximum of four classes per semester.
•An employee cannot take part in more than five projects.
•The salary of an employee cannot exceed the salary of the employee’s
manager.
43. Other Constraints
43
The Entity Relationship Data Model
Business Rules
Business rules are obtained from users when gathering requirements.
The requirements-gathering process is very important, and its results
should be verified by the user before the database design is built. If the
business rules are incorrect, the design will be incorrect, and ultimately
the application built will not function as expected by the users.
Some examples of business rules are:
•A teacher can teach many students.
•A class can have a maximum of 35 students.
•A course can be taught many times, but by only one instructor.
•Not all teachers teach classes.
46. Cardinality
• Defines the numerical attributes of the relationship between two
entities or entity sets.
The three main cardinal relationships are one-to-one, one-to-many,
and many-many.
• A one-to-one example: would be one student associated with one
mailing address.
• A one-to-many example (or many-to-one, depending on the
relationship direction): One student registers for multiple courses,
but all those courses have a single line back to that one student.
• Many-to-many example: Students as a group are associated with
multiple faculty members, and faculty members in turn are associated
The Entity Relationship Data Model
47. Cardinality
Cardinality views: Cardinality can be shown as look-across
or same-side, depending on where the symbols are shown.
Cardinality constraints: The minimum or maximum
numbers that apply to a relationship.
Phases of Database Design
Conceptual Design
47
53. Superclass and Subclass relationships arise during schema
design due to the process of specialization and generalization
Specialization: process of classifying a class of objects into
more specialized subclasses
E.g., during design, we begin with an employee entity set. We
then specialize the employee set into different types of
employees.
Generalization: Reverse of specialization -- it is a process of
synthesis of two or more (lower level) entity sets to produce a
higher-level entity set.
E.g., during design, we have identified a car, a sports utility
Super/Subclasses
Phases of Database Design
Conceptual Design
53
54. Super/Subclasses
Generalisation is the Superclass concept
An entity with one or more distinct subgroupings
Specialisation is the Subclass concept
An entity of a distinct subgrouping
Staff
Full-Time Part-Time
Superclass
Subclasses
Phases of Database Design
Conceptual Design
54
55. Super/Subclasses
Staff has a superclass/subclass relationship
With 2 subclasses
The relationship is ONE-TO-ONE
The super/subclass structure
Avoids modelling different attributes in the
same entity
Avoids therefore nulls
Models common attributes in the superclass
Models unshared attributes in the
subclasses
Phases of Database Design
Conceptual Design
Full-
Time
Staff
Part-
Time
55