0% found this document useful (0 votes)
30 views18 pages

Relational Data Model & Relational Constraints (Ch.5)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
30 views18 pages

Relational Data Model & Relational Constraints (Ch.5)

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 18

Relational Data Model &

Relational Constraints
(Ch.5)
Content

1. What is Relational model


2. Characteristics
3. Relational constrains
4. Representation of schemas
5. Operations on relations and constraints

1 Database Design & Applications


Relational
Model
Edgar Codd proposed Relational Data Model in 1970.
It is a representational or implementation data model.

Using this representational (or implementation) model we


represent a database as collection of relations.

The notion of relation here is different from the notion of


relationship used in ER modeling.

Relation is the main construct for representing data in


relational model.
Every relation consists of a relation schema and Relation
instance.

2 Database Design & Applications


R (A1, A2, A3,……,An)
Relation Schema is denoted by
Relation name Attribute list

The number of columns in a relation is known as its degree or arity’.

Relation instance or Relation State (r) of R (thought of as a table)


Each row in the table represents a collection of related data.
Each row contains facts about some entity of same entity-set.

R = (A1, A2, A3,……., An)


r(R) is a set of n tuples in R
r = {t1, t2, t3,…….,tn}
r is an instance of R each t is a tuple and is a ordered list of values.

t = (v1 , v2 ,…, vn ) where vi is an element of domain of Ai

3 Database Design & Applications


Entities of each type/set are stored as rows in a single relation.

Hence in general, a relation corresponds to a single entity type in


ER diagram.
In some cases a relationship between two entities can have some
specific attributes which can be captured in a relation (table).

A row is called a tuple.


The columns of the table represent attributes of that entity type.

The column header is known as attribute or field.


Data type or format of an attribute: is the format of data for that
attribute. Ex. Character strings, numeric, alphanumeric etc.

Values that can appear in a column for any row is called the
domain of that attribute.
3 Database Design & Applications
Relational Database Schema is denoted by

S ={R1, R2, ……,Rn}

Database Relations in the


name database (tables)

4 Database Design & Applications


Attribute A of relation R is accessed by notation- R.A.

Ex: Student (name, age, branch). Here Student is the relation name.
Student.age - denotes age attribute of Student
relation.

Characteristics of a Relation:

❖ Ordering of tuples is not significant.

❖ Ordering of values in a tuple is important.

❖Values in a tuple under each column must be atomic (simple


& single).
5 Database Design & Applications
5 Database Design & Applications
Relational Model
Terminology
Informal Terms Formal Terms
Table Relation
Column Header Attribute
All possible Column Domain
Values
Row Tuple
Table Definition Schema of a Relation
Populated Table State of the Relation

Database Design & Applications


Relational
Constraints
Constraints are restrictions on data of a relation.

❑Domain level Constrains – Format of data Ex.


Character numeric etc.
Semantic – Not
NULL etc.
❑Entity integrity constraints – Primary key,
unique key

❑ Referential integrity constraints– Foreign key

Database Design & Applications


Relational
Constraints
❑ Dependencies –
Functional dependency : What attributes value
defines the value of another attribute is known
as dependency.

This concept is used in database design.

Database Design & Applications


Referential
integrity
The Referential Integrity constraint is specified
between two relations and is used to maintain
consistency among the tuples of two relations.
FK
PK
R1 R2
a b c p q r

c in R1 refers to p in R2

The FK attribute R1 has the same domain as the primary key


attribute of R2.

The attribute c in R1 is said to reference the attribute p in R2.


Database Design & Applications
Referential
integrity
The value of FK in a tuple t of R1 either occurs as a
value under p in R2 for some tuple, or is a NULL.

R1 → is known as referencing relation


R2 →is known as referenced relation

Constraints can be specified while defining the structure


& also as triggers.

Database Design & Applications


Relational
Schema
Representation

Database Design & Applications


Relational
Schema
Representation

Database Design & Applications


Actions need to be taken when FK is set , on operations like
update, insert, and delete. FK
PK
R1 R2
a b c p q r

c in R1 refers to p in R2

If insert a tuple in R1 where the value for c is not in p of R2, then don’t
allow.

What if a tuple in R2 is deleted:


Cascade, don’t allow, set to default, set to null.

What if update on R2’s p happens:


Cascade, don’t allow, set to default, set to null.

Database Design & Applications


Operations on Relations
and constraints
The following table indicates the constraints need to be taken care while
performing certain operations on a relation.

Operation on relations Constraints need to be


taken care
Insert Null, Not Null, PK, unique, FK,
format, Domain

Delete FK

Update Null, Not Null, PK, unique, FK,


domain, and Semantic

Database Design & Applications


Operations on Relations
and
Emp
constraints
FK Dept
eid ename age dno dnum dname dloc Cascade
101 kiran 28 10 Set to null
10 Mark Che
Set to default
105 Gopi 32 20 20 Prod Hyd Restrict/Reject
121 Ahmed 29 20 30 Acct Bgl
136 John 28 20
138 Mike 30 30 Operation Care for constraints
143 Ali 38 10 Insert PK, Unique, null, notnull,
format
Operation Care for constraints Update PK, Unique, null, notnull,
Insert PK, Unique, null, notnull, format, FK
format, FK Delete FK
Update PK, Unique, null, notnull,
format, FK
Delete No care

Database Design & Applications


Summary
✔ What are basics of relational model
✔ Relation instance
✔ Relational data constraints
✔ Referential integrity
✔ Relational scheme representation
✔ Operations on relations and constraints

Database Design & Applications

You might also like