Chapter No 2: Relational Data Model and Security and Integrity Specification
Chapter No 2: Relational Data Model and Security and Integrity Specification
Chapter No 2: Relational Data Model and Security and Integrity Specification
DATA MODEL
It is a collection of tools used for describing data, relationships among
data, data semantics and consistency constraints.
This is the way which describes the design of the database at physical,
logical and view level.
Different categories of Data models are
Relational Model
Network Model
Hierarchical Model
ER Model
Cust_id
CUSTOMER
Cust_name
Address
ACCOUNT
Ac_no
Balance
ATM_NO
ATM_CARD
ATM_N
O
PIN
CVV
.
C101
Sameer
A101
200000
2000310012
Pune
A101
2000310012
2278
134
Ac_no
Root Node
C102
Ajay
A102
300000
2000310015
Bangalore
A102
2000310015
4587
475
Leaf Node
Cust_id
CUSTOMER
Ac_no
ACCOUNT
C101
C102
Sameer
Ajay
Pune
Bangalore
Cust_name
Balance
Address
Ac_no
ATM_NO
A101,A103
A102,A103
A101
200000
2000310012
A103
300000
2000310015
A102
300000
2000310015
ER Model
o ER model is a Entity Relationship Model.
o It is a graphical representation of database including relationships,
constraints, roles and cardinalities in database.
o Components of ER model
o Entity Set
o Relationship Set
o Attribute
Entity
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.
Attribute
Attributes are descriptive properties possessed by each member of an entity set. An
entity is represented by a set of attributes.
For example Possible attributes of the customer entity set are customer_id, customername, customer_street and customer_city.
Relationship
A relationship is an association among several entities.
For example, we can define a relationship that associates customer Hayes with loan L15. This relationship specifies that Hayes is a customer with loan number L-15.
Types of Attributes :
Simple Attribute
Multivalued Attribute
Derived Attribute
Composite Attribute
Role of Entity
The function that an entity plays in a relationship is called that entitys role.
We indicate roles in E-R diagrams by labeling the lines that connect diamonds
to rectangles. Figure 2.12 shows the role indicators manager and worker between
the employee entity set and the works-for relationship set.
An entity set may not have sufficient attributes to form a primary key. Such an
entity set is termed a weak entity set.
For a weak entity set to be meaningful, it must be associated with another entity
set, called the identifying or owner entity set.
PERSON
PAN CARD
Query Language
A query language is a language in which a user requests information from the database.
These languages are usually on a level higher than that of a standard database
programming language.
Query languages can be categorized as either procedural or nonprocedural.
In a procedural language, the user instructs the system to perform a sequence of operations on
the database to compute the desired result.
For example Relational Algebra
In a nonprocedural language, the user describes the desired information without giving a
specific procedure for obtaining that information.
For Example Relational Calculus
Relational Algebra
o
o
o
Unary Operations
o Select
o Project
o Rename
Binary Operations
o Union
o Intersection
o Set Difference
o Cartesian Product
Select Operation
o Select records from relation that satisfy the selection condition or search condition.
o Lower case Greek letter sigma ( ) is used to denote selection.
o Selection criteria or selection condition appears as subscript to sigma.
o Consider schema BOOK (B_ID,TITLE,AUTHOR,YEAR,PRICE).
o Syntax
(Selection condition)
(Relation)
o Example
Extract record of books having price less than 450/-
(BOOK)
Project Operation
o Project operation display certain columns or attributes from table/relation.
o Lower case Greek letter pi ( ) is used to denote project operation.
o Column names appears as subscript to pi.
o Consider schema BOOK (B_ID,TITLE,AUTHOR,YEAR,PRICE).
o Syntax
(Relation)
o Example
Extract title and author of books from BOOK relation
(title , author)
(BOOK)
Rename Operation
2.
3.
1.
Syntax :
s (R)
new name of relation
Example :
arkp_stud (student)
2.
3.
Example :
Example :
Union Operation
o Union operation is a binary operation.
o It returns all data values that appear in either or both of the two relations.
o Denoted by symbol .
Syntax :
Relation 1 Relation 2
Example :
Cust_name (borrower )
BORROWER
Cust_name (depositor)
DEPOSITOR
BORROWER
union
DEPOSITOR
Cust_name
Loan_no
Cust_name
Acount_no
Adams
L_16
Adams
A_102
John
L_12
Johnson
A_105
John
Smith
L_13
Sam
A_209
Smith
Cust_name
Adams
Johnson
Sam
Intersection Operation
o Intersection operation is also a binary operation.
o It returns all data values which are common in two or more relations.
o Denoted by symbol
Relation 1 Relation 2
Syntax :
Example :
Cust_name (borrower )
BORROWER
Cust_name (depositor)
DEPOSITOR
Cust_name
Loan_no
Cust_name
Acount_no
Adams
L_16
Adams
A_102
John
L_12
Johnson
A_105
Smith
L_13
Sam
A_209
BORROWER
intersection
DEPOSITOR
Cust_name
Adams
Cust_name (borrower )
BORROWER
Cust_name (depositor)
DEPOSITOR
Cust_name
Loan_no
Cust_name
Acount_no
Adams
L_16
Adams
A_102
John
L_12
Johnson
A_105
Smith
L_13
Sam
A_209
BORROWER
set difference
DEPOSITOR
Cust_name
John
Smith
Example :
Relation 1
borrower
Relation 2
depositor
BRROWER DEPOSITOR
BORROWER
Cust_name
Loan_no
Cust_name
Loan_no
Cust_name
Acount_no
Adams
L_16
Adams
L_16
Adams
A_102
John
L_12
Adams
L_16
Johnson
A_105
Smith
L_13
Adams
L_16
Sam
A_209
John
L_12
Adams
A_102
John
L_12
Johnson
A_105
DEPOSITOR
Cust_name
Acount_no
John
L_12
Sam
A_209
Adams
A_102
Smith
L_13
Adams
A_102
Johnson
A_105
Smith
L_13
Johnson
A_105
Sam
A_209
Smith
L_13
Sam
A_209
Relational Calculus
It is a non procedural query language while relational algebra is procedural.
There are two variant of relational calculus
Tuple Relational Calculus (TRC)
Domain Relational Calculus (DRC)
Tuple Relational Calculus
SAILORS
sid
sname
rating
age
22
Dustin
45
29
Brutus
29
31
Lubber
39
32
Andy
42
58
Rusty
10
35
Table : SAILORS
FUNCTIONAL DEPENDENCY
A
a1
b1
c1
d1
a1
b1
c1
d2
a1
b2
c2
d1
a2
b1
Fig. A relation that satisfy FD
c3
AB C
d1
&
Now consider
T1(C) = C1
T2(C) = C1
Therefore we can say that
AB C
NORMALIZATION
Normalization can be defined as a process of
o Minimizing Redundancy
o Minimizing Inconsistency
o Minimizing the insertion, deletion and update anomalies from the database.
There are different type of normal forms having there own condition OR criteria for normalization.
Different normal forms are
StudentID Semester.
Note that if a row was added where the student had a different value of semester
that the FD would no longer exist. This means that the FD is implied by the data
as it is possible to have values that would invalidate the FD.
DNUMBER
DMGR_NO
DLOCATIONS
Research
05
3320
Administration
04
2924
{Ahmedabad, Nagpur}
Headquarter
01
2221
{Chennai}
Fig. DEPARTMENT (not in 1NF )
DNUMBER DLOCATIONS
DNAME
DNUMBER
DMGR_NO
Research
05
3320
Administration
04
2924
Headquarter
01
2221
05
Delhi
05
Bombay
05
Calcutta
04
Ahmedabad
04
Nagpur
01
Chennai
Property_ID City_Name
Sector_No
Area
Price
Table : PROPERTY
Property_ID City_Name
Sector_No
Table : PROPERTY_1
City_Name
Tax_Rate
Table : PROPERTY_2
Area
Price
Tax_Rate
Property_ID City_Name
Sector_No
Area
Table : PROPERTY_1
Property_ID City_Name
Sector_No
Table : PROPERTY_11
Sector_No
Area
Table : PROPERTY_12
Price
Price