Title: Relational Data Model
1Relational Model
2Outline
- Background and terminology
- Foundations
- Data Structure
- Data Integrity
- Data Manipulation
3What is Relational Model
- A data model based on relations and their
- representation as tables first proposed by
- E.F. Codd in 1978.
- Supports powerful, yet simple and declara-
- tive languages with which operations on
- data are expressed.
4Database Relations
Attributes
VOTER
Tuple
5Basic Concepts
- Relation Table
- Tuple Row or Record
- Cardinality of rows
- Attribute Column or Field
- Degree of Column
- Domain Pool of legal value
6Basic Concepts
- Relation scheme
-
- Set of attribute names for a relation
- e.g. student (ssn, name, address, phone, ...)
- class(class, title, ...)
7Example
CITYINFO relation
8Properties of the Relational Model
- All data must be presented in tabular form.
- All data must be atomic.
- No duplicate tuples are allowed.
- Tuples and attributes may be rearranged in almost
any order
9Example
CAND (NAME, DATE-OF-BIRTH, JOB)
10Data Integrity
- Data must satisfy certain integrity rules and
constraints before it is allowed to be entered
into the relation. - Entity Integrity
- Referential Integrity
11Keys
- Relations have sets of one or more attributes
that - serve as a key.
- The following two properties must be satisfied
for - key
- 1. Unique Identification
- 2. Nonredundancy
12Keys
- Super key
- Candidate key
- Primary key
- Secondary key
- Foreign key
- Composite key
13Reducing E-R Diagrams to tables
E-R diagram.
date
transaction- number
street
customer- city
date
social security
amount
account- number
customer- name
balance
transaction
log
customer
account
CustAcct
-
14Developing Relational Models
- Representation of Strong Entity Sets
- Representation of Weak Entity Sets
- Multivalued Attributes of Entities
15 Example entity set by a table called ACCOUNT
with two columns gt account
number gt balance
The account table
16Example
Entity set Customer (customer name, social
security, street, customer city)
The customer table.
17Elimination of a multivalued attribute from an
entity
PRODUCT_CODE MATERIAL_CODES (1,n) DESCRIPTION PRIC
E
PRODUCT
PRODUCT_CODE DESCRIPTION PRICE
PRODUCT
PRODUCT_CODE MATERIAL_CODE
PRODUCT_MATERIAL
18LAST_NAME AGE SEX
PERSON
Composite Attributes of Entities
STREET
ADDRESS
CITY
STATE
(a) Schema with a composite attribute
LAST_NAME AGE SEX STREET CITY
PERSON
STATE
(b) Composite attribute reduced to components
LAST_NAME AGE SEX ADDRESS
PERSON
(c) Composite attribute considered as single
attribute
Elimination of a composite attribute
19Table CUST ACCT has three columns
20Example
branch- city
CAB
branch- name
assets
branch
street
customer- city
social- security
balance
account- number
customer- name
customer
CAB
account
E-R diagram with a ternary relationship
21The CAB table.
22Multivalued Attributes of Relationships
If the multivalued attribute belongs to a
relationship R between entities E1 and E2, create
a separate, new entity to represent it. The new
entity includes one or two attributes taken from
E1, E2 or both, depending on the type of the
relationship. 1. one-to-one include primary key
of either E1 or E2 2. one-to-many include
primary key of E2 3. many-to-many include
primary keys of E1 and E2 (e.g. students take
courses)
23INSTRUCTOR_SSN DEPARTMENT PHONE_NUMBER
INSTRUCTOR
Elimination of a multivalued attribute from a
relationship by creating a separate entity
INSTRUCTOR_SSN DEPARTMENT PHONE_NUMBER
INSTRUCTOR
MAX_NO_STUD
OFFERS
COURSE_NO
COURSE
INSTRUCTOR_NNS COURSE_NO SEMESTER
COURSE_ OFFERING
24Recursive Relationships
NAME
DATE_OF_BIRTH
EMPLOYEE
IS_MANAGER_OF
IS_SUBORD
MANAGER_ OF
Translation?
25Generalization and Specialization
--- Two ways of creating tables from E-R diagrams
account
Generalization
ISA
savings-account
checking-account
26Generalization
Create a table for the higher-level entity. For
each lower-level entity, create a table which
includes a column for each of the descriptive
attributes of that entity plus a column for
each attribute of the primary key of the
high-level entity.
27Specification
Do not create a table for the higher level
entity. Create a table for each lower-level
entity which includes a column for each
attribute of the entity plus a column for each
attribute of the higher-level entity.
28Advantages of the Relational Model
- True data independence
- Communicability
- Set processing
- Accessing information