Chapter No 2 :
Relational Data Model and Security and Integrity SpecificationMarks = 22
2.1----------------------------------- (10 Marks)• Data Model
• Network Model• Hierarchical Model• Relational Model
• Relational Model: - Basic Concepts Attributes and Domains. Key Concepts:- Candidate key, Primary key, Foreign key and Super key.
• E-R model, Components of ER Model, Types of attributes, role indicator, weak & strong entity set.
• Enhanced ER Model: Introduction, Specialization & Generalization.
2.2 ----------------------------------- (12 Marks)
• Relational Algebra and Relational Calculus.• Database Design: Relational database Design, Functional
dependencies, Normalization based on functional dependencies,
• Normal forms: 1NF, 2NF, 3NF, BCNF. Normalization based on multivalued dependencies, Normalization based on Join dependencies.
• Integrity Constraints: Domain Integrity Constraints, Entity integrity Constraints, Referential Integrity Constraints & on delete cascade.
• Database Security: introduction, Data security requirements.
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
Hierarchical Data Modelo Developed in 1960.o It represent database as upside down tree.o Parent- Child relationship is present.o It support only one to many relationshipo Starting point is called as Root , subpart is called as node and the last node called as leaf
node.
Network Data Modelo Developed in 1964 and standardized in 1971.o It represent database as a arbitrary graph.o There is no parent-child relationship between nodes.o It supports many to many relationship.
Cust_id Cust_name Address Ac_no
Ac_no Balance ATM_NO
CUSTOMER
ACCOUNT
C101 Sameer
Pune A101 C102 Ajay Bangalore
A102
A101
200000
2000310012
A102
300000
2000310015
ATM_CARD ATM_NO
PIN CVV
2000310012
2278 134
2000310015
4587
475
.
Fig. Hierarchical Data Model
Root Node
Leaf Node
Cust_id Cust_name Address Ac_no
Ac_no Balance ATM_NO
CUSTOMER
ACCOUNT
C101 Sameer
Pune A101,A103
C102 Ajay Bangalore
A102,A103
A101
200000
2000310012
A102 300000
2000310015
Fig. Network Data Model
A103
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
oEntity SetoRelationship SetoAttribute
EntityAn 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.
AttributeAttributes 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, customer-name, customer_street and customer_city.
RelationshipA relationship is an association among several entities.
For example, we can define a relationship that associates customer Hayes with loan L-15. This relationship specifies that Hayes is a customer with loan number L-15.
Symbols For ER Diagrams
Rectangles, which represent entity sets.
Ellipses, which represent attributes.
Diamonds, which represent relationship sets.
Lines, which link attributes to entity sets
and entity sets to relationship sets.
Double ellipses, which represent multivalued attributes.
Dashed ellipses, which denote derived attributes.
Double rectangles, which represent weak entity sets
Types of Attributes :• Simple Attribute
• Primary Key Attribute
• Multivalued Attribute
• Derived Attribute
• Composite Attribute
Role of EntityThe function that an entity plays in a relationship is called that entity’s 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.
Strong Entity Set• An entity set that has a primary key is termed a strong entity set.
Weak Entity 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.
Types of Relationships / Mapping Cardinalities
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 Algebrao The relational algebra is a procedural query language.o It consists of a set of operations that take one or two relations as input and produce a new
relation as their result. o The fundamental operations in the relational algebra are select, project, union, set difference,
Cartesian product, and rename.
Unary operations Binary operations
Unary Operationso Selecto Projecto Rename
Binary Operationso Uniono Intersectiono Set Differenceo 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/-”
σ(price < 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
π(Column Name1, Column Name2, ….., Column Name n) (Relation)o Example
“Extract title and author of books from BOOK relation”
π(title , author) (BOOK)
Rename Operation
• Rename operation use to rename relation/table name as well as attribute/column
names.
• Lower case Greek letter rho (ρ ) is used to denote rename operation.
1. Rename only relation/table name.
2. Rename only attribute/column names.
3. Rename both relation/table name and attribute/column names at a time.
1. Rename only relation/table name.
Syntax : ρs (R)
new name of relation old name of relation
Example : ρarkp_stud (student)
2. Rename only attribute/column names.
3. Rename both relation/table name and attribute/column names at a
time.
Rename attribute/column names
Syntax : ρ (new names for attributes) (R)
name of relation
Example : ρ (s_rn, s_name, s_class) (student)
Rename relation/table name as well as attribute names
Syntax : ρs (new names for attributes) (R)
new name of relation old name of relation
Example : ρarkp_stud(s_rn, s_name, s_class) (student)
Union Operationo 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 :
BORROWER
Cust_name
Loan_no
Adams L_16
John L_12
Smith L_13
DEPOSITOR
Cust_name
Acount_no
Adams A_102
Johnson A_105
Sam A_209
BORROWER union
DEPOSITOR
Cust_name
Adams
John
Smith
Johnson
Sam
Π Cust_name (borrower ) ∪ Π Cust_name (depositor)
Intersection Operationo 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 ∩ .
Syntax : Relation 1 ∩ Relation 2
Example :
BORROWER
Cust_name
Loan_no
Adams L_16
John L_12
Smith L_13
DEPOSITOR
Cust_name
Acount_no
Adams A_102
Johnson A_105
Sam A_209
BORROWER intersection DEPOSITOR
Cust_name
Adams
Π Cust_name (borrower ) ∩ Π Cust_name (depositor)
Set Difference Operationo Set Difference operation is also a binary operation.o Set Difference operation allows us to find tuples which are present in first relation but not in
other relation.o Denoted by symbol “ “ .
Syntax : Relation 1 Relation 2
Example :
BORROWER
Cust_name
Loan_no
Adams L_16
John L_12
Smith L_13
DEPOSITOR
Cust_name
Acount_no
Adams A_102
Johnson A_105
Sam A_209
BORROWER set difference DEPOSITOR
Cust_name
John
Smith
Π Cust_name (borrower ) Π Cust_name (depositor)
Cartesian product Operationo Cartesian product operation is also a binary operation.o Cartesian product operation combines two or more relations in such a way that
each row of one relation combine with each row of other relation.
o Denoted by symbol “ × “ .
Syntax : Relation 1 × Relation 2
Example :borrower × depositor
BORROWER
Cust_name
Loan_no
Adams L_16
John L_12
Smith L_13
DEPOSITOR
Cust_name
Acount_no
Adams A_102
Johnson A_105
Sam A_209
BRROWER × DEPOSITOR
Cust_name Loan_no Cust_name Acount_no
Adams L_16 Adams A_102
Adams L_16 Johnson A_105
Adams L_16 Sam A_209
John L_12 Adams A_102
John L_12 Johnson A_105
John L_12 Sam A_209
Smith L_13 Adams A_102
Smith L_13 Johnson A_105
Smith L_13 Sam A_209
Fig. Cartesian Product
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 Calculuso In TRC , All operations are depend on tuples.o A tuple variable is a variable that takes tuples of a particular relation. Tuple variable has same
number of columns as in relation.o A tuple relational calculus query has the form
{ T | p(T) }
where T is tuple variable
p(T) is formula that operates/describe tuple variable (T)o Example
query = “find all sailors with a rating above 7”
the tuple relational calculus query will be
{ S | S ϵ sailors ˄ S.rating > 7 ˄ S.AGE<30}
Domain Relational Calculuso In DRC , All operations are depend on attribute domains (columns).o A domain variable is a variable that contains values from some attribute domains. o A domain relational calculus query has the form
{ (X1,X2,….,Xn) | p(X1,X2,….,Xn)
where each Xi is either a domain variable or constant
p(X1,X2,….,Xn) is formula that operates/describe tuple variable (T)o Example
query = “find all sailors with a rating above 7 AND AGE IS BELOW 30”
the tuple relational calculus query will be
{ (I,N,T,A) | (I,N,T,A) ϵ sailors ˄ T > 7 ˄ A<30 }
SAILORS
sid sname rating age
22 Dustin 7 45
29 Brutus 1 29
31 Lubber 7 39
32 Andy 8 42
58 Rusty 10 35
Table : SAILORS
A B C D
a1 b1 c1 d1
a1 b1 c1 d2
a1 b2 c2 d1
a2 b1 c3 d1
If AB C then following condition must be present in relation R
T1.(AB) =(a1b1) &T2.(AB)=(a1b1)
Now consider T1(C) = C1T2(C) = C1
Therefore we can say that
AB C
Fig. A relation that satisfy FD AB C
FUNCTIONAL DEPENDENCY
NORMALIZATION Normalization can be defined as a process of
o Minimizing Redundancyo Minimizing Inconsistencyo 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
First Normal form ( 1NF ) Second Normal form (2 NF ) Third Normal form (3 NF ) Boyce/Codd Normal form (BCNF )
First Normal form ( 1NF )
“ A relation is in 1 NF if and only if every attribute of a relation is single OR atomic”
DNAME DNUMBER DMGR_NO DLOCATIONS
Research 05 3320 {Delhi, Bombay,
Calcutta}Administration
04 2924 {Ahmedabad,
Nagpur}Headquarter 01 2221 {Chennai}
Fig. DEPARTMENT (not in 1NF )
DNAME DNUMBER DMGR_NO
Research 05 3320
Administration
04 2924
Headquarter 01 2221
DNUMBER
DLOCATIONS
05 Delhi
05 Bombay
05 Calcutta
04 Ahmedabad
04 Nagpur
01 Chennai
Fig. DEPARTMENT (In 1NF )
Fig. DLOCATIONS (In 1NF )
Second Normal Form ( 2NF )
“ A relation is in second normal if and only if it is in 1NF every nonprime attribute is
fully functional depend on primary key of a relation.”
Property_ID
City_Name
Sector_No Area Price Tax_Rate
Property_ID
City_Name
Sector_No Area Price
Table : PROPERTY
Table : PROPERTY_1
Table : PROPERTY_2
City_Name Tax_Rate
Third Normal Form ( 3NF )
“ A relation is in third normal form if and only if, it is in 2NF and there is no
transitive dependency in a relation.”
Property_ID
City_Name
Sector_No Price
Sector_No Area
Property_ID
City_Name
Sector_No Area Price
Table : PROPERTY_11
Table : PROPERTY_12
Table : PROPERTY_1
Boyc Codd Normal Form ( BCNF )
“ A relation is in BCNF if and only if, it is in 2NF and every determinant is a
candidate key.”
clientNo, interviewDate (Primary Key)
interviewDate, staffNo roomNo
ClientNo
interviewDate
interviewTime staffNo roomNo
CR76 13-May-02 10.30 SG5 G101
CR77 13-May-02 12.00 SG5 G101
CR74 13-May-02 12.00 SG37 G102
CR56 1-Jul-02 10.30 SG5 G102