Database Management System 1
Database Management System 1
Database System
Chittaranjan Pradhan
System 1 Limitations of
File-Processing
Systems
DBMS
Database Types
Advantages of DBMS
over File System
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
1.1
Introduction to
Data & Information Database System
Chittaranjan Pradhan
Limitations of
File-Processing
Systems
Database
• Data
DBMS
• Raw facts, unprocessed facts
Database Types
• Refers to what is actually stored Advantages of DBMS
over File System
• Information
• Result of processing raw data
• Refers to meaning of the data, understood by the user
1.2
Introduction to
Limitations of File-Processing Systems Database System
Chittaranjan Pradhan
Limitations of
File-Processing
Systems
Database
DBMS
Database Types
Advantages of DBMS
over File System
• Redundancy problem
• Repetitive data
• Data-inconsistency problem
• Incorrectness of data
• Lack of data integration
• Complex and time consuming
1.3
Introduction to
Database Database System
Chittaranjan Pradhan
stores: Limitations of
File-Processing
• End- user data: raw facts of interest to the end-user Systems
Database
• Meta data: through which the end-user data are integrated
DBMS
& managed. The metadata provides a description of the
Database Types
data characteristics and the set of relationships that link the
Advantages of DBMS
data found within the database over File System
1.4
Introduction to
DBMS Database System
Chittaranjan Pradhan
• DBMS serves as the intermediary between the user & the Advantages of DBMS
over File System
database
1.5
Introduction to
Database Types Database System
Chittaranjan Pradhan
Chittaranjan Pradhan
Limitations of
File-Processing
• Controlling Redundancy & Inconsistency Systems
Database
• Allows Data Sharing
DBMS
• Restricting Unauthorized Access Database Types
Advantages of DBMS
• Providing Storage Structures for efficient query processing over File System
1.7
Data Model
Chittaranjan Pradhan
System 2
Blocks
Hierarchical Model
Network Model
Entity-
Relationship(ER)
Model
Object-Oriented(OO)
Model
Object-Relational(OR)
Model
Semi-structured Model
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
2.1
Data Model
Data Model
Chittaranjan Pradhan
Data Model
Data Model Basic Building
Blocks
Hierarchical Model
Data Model Network Model
Object-Oriented(OO)
describe the design of a database Model
Object-Relational(OR)
Model
• It is relatively simple representation, usually graphical, of Semi-structured Model
complex real-world data structures
• Data modeling is considered as the most important part of
the database design process
2.2
Data Model
Data Model Basic Building Blocks
Chittaranjan Pradhan
Entity-
Relationship(ER)
Entity Set Model
Object-Oriented(OO)
Set of entities of the same type that share the same properties Model
Semi-structured Model
Attribute
An attribute is a characteristic of an entity
Constraints
A constraint is a restriction placed on the data. Constraints are
important because they help to ensure data integrity
2.3
Data Model
Data Model Basic Building Blocks...
Chittaranjan Pradhan
Relationship
A relationship describes an association among entities. Data Model
Data Model Basic Building
Different types of relationship are: Blocks
Hierarchical Model
Relational Model
Entity-
Relationship(ER)
Model
Object-Oriented(OO)
Model
Object-Relational(OR)
• One-to-Many (1:M) Relationship: Model
Semi-structured Model
2.4
Data Model
Hierarchical Model
Chittaranjan Pradhan
Object-Relational(OR)
Model
Semi-structured Model
2.5
Data Model
Hierarchical Model...
Chittaranjan Pradhan
Data Model
Data Model Basic Building
Blocks
• Efficient storage for data that have a clear hierarchy Network Model
2.6
Data Model
Network Model
Chittaranjan Pradhan
Hierarchical Model
relationships more effectively than the hierarchical model, to
Network Model
improve database performance, and to impose a database Relational Model
standard. A user perceives the network model as a collection Entity-
of records in 1:M relationships Relationship(ER)
Model
Object-Oriented(OO)
Model
Object-Relational(OR)
Model
Semi-structured Model
2.7
Data Model
Network Model...
Chittaranjan Pradhan
• Advantages:
Data Model
• It represents complex data relationships better than Data Model Basic Building
Blocks
hierarchical models Hierarchical Model
• It handles more relationship types, such as M: N and
Network Model
multi-parent Relational Model
• Data access is more flexible than hierarchical model Entity-
• Improved database performance Relationship(ER)
Model
• It includes DDL and DML
Object-Oriented(OO)
Model
• Disadvantages:
Object-Relational(OR)
• System complexity limits efficiency Model
management
• Structural changes require changes in all application
programs
• Database contains a complex array of pointers that thread
through a set of records
• Put heavy pressure on programmers due the complex
structure
• Networks can become chaotic unless planned carefully
2.8
Data Model
Relational Model
Chittaranjan Pradhan
Relational Model
Entity-
The most important advantage of the RDBMS is its ability to Relationship(ER)
Model
hide the complexities of the relational model from the user.
Object-Oriented(OO)
Another reason for the relational data model’s rise to Model
2.9
Data Model
Relational Model...
Chittaranjan Pradhan
Data Model
Data Model Basic Building
• Advantages: Blocks
Network Model
application programs
Relational Model
• Tabular view substantially improves conceptual simplicity,
Entity-
thereby promoting easier database design, implementation, Relationship(ER)
management and use Model
Semi-structured Model
• Disadvantages:
• Conceptual simplicity gives relatively untrained people the
tools to use a good system poorly
• It may promote islands of information problems as
individuals and departments can easily develop their own
applications
2.10
Data Model
Entity-Relationship(ER) Model
Chittaranjan Pradhan
Data Model
Entity-Relationship(ER) Model Data Model Basic Building
Blocks
Peter Chen first introduced the ER data model in 1976; it was Hierarchical Model
the graphical representation of entities and their relationships Network Model
in a database structure that quickly became popular. Thus, the Relational Model
Object-Oriented(OO)
Model
ER models are normally represented in an ER diagram Object-Relational(OR)
Model
Semi-structured Model
2.11
Data Model
Entity-Relationship(ER) Model...
Chittaranjan Pradhan
Data Model
Data Model Basic Building
Blocks
Hierarchical Model
• Advantages: Network Model
• Visual modeling yields exceptional conceptual simplicity Relational Model
• Visual representation makes it an effective communication Entity-
Relationship(ER)
tool Model
• It is integrated with dominant relational model Object-Oriented(OO)
Model
• Disadvantages:
Object-Relational(OR)
• There is limited constraint representation Model
Semi-structured Model
• There is limited relationship representation
• There is no DML
• Loss of information content when attributes are removed
from entities to avoid crowded displays
2.12
Data Model
Object-Oriented(OO) Model
Chittaranjan Pradhan
Object-Oriented(OO) Model
In object-oriented data model, both data and their relationships Data Model
Data Model Basic Building
are contained in a single structure called an object. Like the Blocks
Network Model
content. But quite unlike an entity, an object includes
Relational Model
information about relationships between the facts within the
Entity-
object, as well as information about its relationships with other Relationship(ER)
Model
Object-Oriented(OO)
Attributes describe the properties of an object. Objects that Model
2.13
Data Model
Object-Oriented(OO) Model...
Chittaranjan Pradhan
Data Model
Data Model Basic Building
Blocks
Hierarchical Model
• Advantages: Network Model
• Semantic content is added Relational Model
2.14
Data Model
Object-Relational(OR) Model
Chittaranjan Pradhan
Object-Relational(OR) Model
The object-oriented data model is somewhat spherical in Data Model
Data Model Basic Building
nature, allowing access to unique elements anywhere within a Blocks
Network Model
performs extremely poorly when retrieving more than a single
Relational Model
data item
Entity-
The relational data model is best suited for retrieval of groups Relationship(ER)
Model
of data, but can also be used to access unique data items fairly Object-Oriented(OO)
efficiently Model
Object-Relational(OR)
Model
Thus, by combining the features of relational data model and Semi-structured Model
2.15
Data Model
Semi-structured Model
Chittaranjan Pradhan
Data Model
Data Model Basic Building
Blocks
Hierarchical Model
Network Model
Relational Model
Semi-structured Model Entity-
Relationship(ER)
The semi-structured data model permits the specification of Model
data where individual data items of the same type may have Object-Oriented(OO)
Model
different sets of attributes. The XML (Extensible Markup Object-Relational(OR)
Language) is widely used to represent semi-structured data. It Model
Semi-structured Model
supports unstructured data
2.16
3-Level Abstraction of
Database
Chittaranjan Pradhan
Database Users
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
3.1
3-Level Abstraction of
3-Level Abstraction of Database Database
Chittaranjan Pradhan
3-Level Abstraction of Database
The goal of the ANSI/SPARC 3-level abstraction is to separate 3-Level Abstraction of
the user applications and the physical database. It deals with Database
Mapping and Data
the data, the relationship between them and the different Independence
3.2
3-Level Abstraction of
3-Level Abstraction of Database... Database
Chittaranjan Pradhan
The external level includes a number of external schemas or Mapping and Data
Independence
user views. Each external schema or user view describes the Database Users
Conceptual Level
The conceptual level has a conceptual schema, which
describes the structure of the whole database for a community
of users. The conceptual schema hides the details of physical
storage structures and concentrates on describing entities,
data types, relationships and constraints
3.3
3-Level Abstraction of
3-Level Abstraction of Database... Database
Chittaranjan Pradhan
3-Level Abstraction of
Database
Mapping and Data
Independence
Database Users
Internal Level
The internal level has an internal schema, which describes the
physical storage structure of the database system. Like
conceptual schema, there is only one internal schema available
for a database. It is the one which is closest to physical storage
The internal schema not only defines the various stored record
types, but also specifies what indices exist, how stored fields
are represented
3.4
3-Level Abstraction of
Mapping and Data Independence Database
Chittaranjan Pradhan
user group refers only to its own external schema. The process Mapping and Data
Independence
Conceptual/Internal Mapping
It defines the correspondence between the conceptual view
and the stored database. Physical Data Independence
indicates that the internal schema can be changed without any
change to the conceptual schema
External/Conceptual Mapping
It defines the correspondence between a particular external
view and the conceptual view. Logical Data Independence
indicates that the conceptual schema can be changed without
affecting the existing external schemas
3.5
3-Level Abstraction of
Database Users Database
Chittaranjan Pradhan
3-Level Abstraction of
Database
Different database users are: Mapping and Data
Independence
Application Programmers
They are computer professionals who write application
programs to access data from the database. Application
programmers can use different tools to develop user interfaces
3.6
3-Level Abstraction of
Database Users... Database
Chittaranjan Pradhan
Sophisticated Users
3-Level Abstraction of
Database
They interact with the system without creating any application Mapping and Data
Independence
program. Rather, they form their requests in a database query
Database Users
language and submit each such query to a query processor.
Analysts who submit queries to explore data in the database
fall in this category
Specialized Users
They are sophisticated users who write specialized database
applications that don’t fit into the traditional data processing
framework
Database Administrator(DBA)
The person who has central control of the whole database
system is called DBA. The DBA coordinates all the activities of
the database system
3.7
3-Level Abstraction of
Database Users... Database
Chittaranjan Pradhan
System 4
Storage Manager
Query Processor
Database Architecture
Disadvantages of
Database Processing
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
4.1
Database Architecture
Data Storage and Querying
Chittaranjan Pradhan
4.2
Database Architecture
Storage Manager
Chittaranjan Pradhan
Storage Manager
Data Storage and
A storage manager is a program module that provides the Querying
interface between the low-level data stored in the database and Storage Manager
Query Processor
the application programs and queries submitted to the system. Database Architecture
The storage manager is responsible for the interaction with the Application
Architecture
file manager. Storage manager is responsible for storing,
Disadvantages of
retrieving and updating data in the database Database Processing
fetching data from the disk storage into main memory. The Storage Manager
Query Processor
Application
The storage manager implements several data structures as Architecture
4.4
Database Architecture
Query Processor
Chittaranjan Pradhan
Application
Architecture
The major components of query processor include:
Disadvantages of
• DDL Interpreter:This is the interpreter used to interpret Database Processing
4.5
Database Architecture
Database Architecture
Chittaranjan Pradhan
The overall database architecture is:
Data Storage and
Querying
Storage Manager
Query Processor
Database Architecture
Application
Architecture
Disadvantages of
Database Processing
4.6
Database Architecture
Application Architecture
Chittaranjan Pradhan
Disadvantages of
• 2-Tier Architecture: Here, the application is partitioned Database Processing
4.7
Database Architecture
Application Architecture...
Chittaranjan Pradhan
Database Architecture
Application
Architecture
Disadvantages of
Database Processing
4.8
Database Architecture
Disadvantages of Database Processing
Chittaranjan Pradhan
The major disadvantages are:
• Larger file size: In order to support all the complex
Data Storage and
functions that it provides to users, a DBMS must be a Querying
Storage Manager
large program that occupies a great amount of disk space Query Processor
Application
• Increased Complexities: The complexity and breadth of Architecture
Chittaranjan Pradhan
System 5 Entity-
Relationship(ER)
Model
Mapping Cardinality
Representation
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
5.1
ER Modeling
Overview of the Database Design Process
Chittaranjan Pradhan
Overview of the
Database Design
• The initial phase of database design is to characterize fully Process
Attribute Types
• Next, the designer chooses a data model and, by applying
Mapping Cardinality
the concepts of the chosen data model, translates these Representation
5.2
ER Modeling
Overview of the Database Design Process...
Chittaranjan Pradhan
Overview of the
Database Design
Process
Entity-
• The process of moving from an abstract data model to the Relationship(ER)
Model
implementation of the database proceeds in two final Attribute Types
design phases: Mapping Cardinality
Representation
• In the logical design phase, the designer maps the
high-level conceptual schema onto the implementation data
model of the database system that will be used. The
implementation data model is typically the Relational data
model
• Finally, the designer uses the resulting system-specific
database schema in the subsequent physical-design phase,
in which the physical features of the database are specified
5.3
ER Modeling
Entity-Relationship(ER) Model
Chittaranjan Pradhan
Overview of the
Entity-Relationship(ER) Model Database Design
Process
model is very much useful in mapping the meaning and Mapping Cardinality
Representation
interactions of real-world enterprises onto a conceptual
schema
Entities
An entity is a thing or object in the real world that is
distinguishable from all other objects, i.e. an entity is an object
of interest to the end user. The set of similar types of entities is
called entity set; which is represented by a rectangle
containing the entity set’s name. The entity set name, a noun,
is usually written in all capital letters
5.4
ER Modeling
Entity-Relationship(ER) Model...
Chittaranjan Pradhan
Attributes
Attributes are characteristics of entities. Attributes are Overview of the
Database Design
represented by ovals and are connected to the respective Process
entity set with lines. In the conceptual modeling, the value of an Entity-
Relationship(ER)
attribute comes from a domain of possible values Model
Attribute Types
NULL Values
An attribute takes a NULL value when an entity doesn’t have a
value for it. The NULL values may indicate not applicable, i.e.
the value doesn’t exist for the entity. NULL can also designate
that an attribute value is unknown. An unknown value may be
either missing or not known. NULL value is an entry in all the
domains 5.5
ER Modeling
Attribute Types
Chittaranjan Pradhan
5.6
ER Modeling
Attribute Types...
Chittaranjan Pradhan
Entity-
are referred to as single-valued attribute. However, attributes Relationship(ER)
Model
that can have more than one value are known as multi-valued
Attribute Types
attributes. It is represented by double oval Mapping Cardinality
Representation
5.7
ER Modeling
Attribute Types...
Chittaranjan Pradhan
Overview of the
Stored and Derived attributes Database Design
Process
The attribute with independent existence is called as stored Entity-
attribute where as the attribute, whose value is depending on Relationship(ER)
Model
other stored attribute, is called as derived attribute. The derived Attribute Types
attribute is represented by the dotted oval Mapping Cardinality
Representation
5.8
ER Modeling
Attribute Types...
Chittaranjan Pradhan
Overview of the
Database Design
Process
Entity-
Descriptive attributes Relationship(ER)
Model
attributes for representing the description about the association Mapping Cardinality
Representation
5.9
ER Modeling
Mapping Cardinality Representation
Chittaranjan Pradhan
M:N relationship
Overview of the
Database Design
An entity in A is associated with any number (zero or more) of Process
Attribute Types
Mapping Cardinality
Representation
5.10
ER Modeling
Mapping Cardinality Representation...
Chittaranjan Pradhan
1:M relationship
Overview of the
An entity in A is associated with any number (zero or more) of Database Design
Process
entities in B; an entity in B, however, is associated with no Entity-
more than 1 entity set of A Relationship(ER)
Model
Attribute Types
Mapping Cardinality
Representation
5.11
ER Modeling
Mapping Cardinality Representation...
Chittaranjan Pradhan
1:1 relationship
Overview of the
Database Design
An entity in A is associated with no more than 1 entity of B; and Process
Attribute Types
Mapping Cardinality
Representation
5.12
ER Modeling...
Chittaranjan Pradhan
Participation
Constraints
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
6.1
ER Modeling...
Keys
Chittaranjan Pradhan
Keys
Keys
A key allows us to identify a set of attributes that suffice to Keys for Relationship sets
Relationship Types
distinguish entities from each other
Participation
Constraints
l..h Representation
• A key is a property of the entity set, rather than of the Alternate Mapping
Cardinality Representation
individual entities Strong Entity sets and
Weak Entity sets
• A super key is a set of one or more attributes that allow us
to identify uniquely an entity in an entity set
• The minimal super keys are called candidate keys
• Primary key is a candidate key that is chosen by the
database designer as the principal means of identifying
entities within an entity set. The primary key can be
represented by underlying the attribute name. The primary
key should be chosen such that its attributes are never or
very rarely changed
• The remaining candidate keys except the primary key are
called as alternate keys
6.2
ER Modeling...
Keys...
Chittaranjan Pradhan
• If none of the columns is a candidate for the primary key in
a table, sometimes database designers use an extra Keys
column as a primary key instead of using a composite key. Keys for Relationship sets
Relationship Types
Such key is known as the surrogate key
Participation
• Foreign key is the set of attributes which is used for Constraints
l..h Representation
referring to another entity set having the primary key. In Alternate Mapping
Cardinality Representation
ER diagram, foreign key can not be represented Strong Entity sets and
Weak Entity sets
6.3
ER Modeling...
Keys for Relationship sets
Chittaranjan Pradhan
Keys
Keys for Relationship sets
Participation
Let R be a relationship set involving entity sets E1 , E2 , ... En . Constraints
l..h Representation
Let PK(Ei ) denotes the set of attributes that forms the primary Alternate Mapping
Cardinality Representation
key for entity set Ei Strong Entity sets and
Weak Entity sets
• If the relationship set R has no descriptive attributes
associated with it, then the set of attributes PK(E1 ) U
PK(E2 ) U ... U PK(En ) describes an individual relationship
in set R
• If the relationship set R has attributes a1 , a2 ... am
associated with it, then the set of attributes PK(E1 ) U
PK(E2 ) U ... U PK(En ) U {a1 ,a2 ,...am } describes an
individual relationship in set R
6.4
ER Modeling...
Keys for Relationship sets...
Chittaranjan Pradhan
M:N relationship
The primary key of the relationship set consists of the union of Keys
Keys for Relationship sets
the primary keys of the entity sets Relationship Types
Participation
Constraints
l..h Representation
Alternate Mapping
Cardinality Representation
1:M relationship
The primary key of the relationship set is the primary key of the
many side entity set
6.5
ER Modeling...
Keys for Relationship sets...
Chittaranjan Pradhan
Keys
Keys for Relationship sets
Relationship Types
6.6
ER Modeling...
Relationship Types
Chittaranjan Pradhan
Relationship Types
A relationship type is a meaningful association among entity Keys
Keys for Relationship sets
types. The degree of a relationship type is defined as the Relationship Types
number of entity sets participating in that relationship type Participation
Constraints
l..h Representation
Binary relationship Alternate Mapping
Cardinality Representation
A relationship type is said to be binary when two entity sets are Strong Entity sets and
Weak Entity sets
involved
Ternary relationship
Relationship types that involve three entity sets are defined as
ternary relationships
6.7
ER Modeling...
Relationship Types...
Chittaranjan Pradhan
Quaternary relationship
A relationship of degree four can be referred to as a quaternary Keys
Keys for Relationship sets
relationship Relationship Types
Participation
Constraints
l..h Representation
Alternate Mapping
Cardinality Representation
Recursive relationship
The participation of an entity set in a relationship type can be
indicated by its role name. When used in recursive relationship
types, role names describe the functionality of the participation
6.8
ER Modeling...
Participation Constraints
Chittaranjan Pradhan
Participation Constraints
The participation constraint for an entity set in a binary Keys
Keys for Relationship sets
relationship type is based on whether an entity of that entity set Relationship Types
needs to be related to an entity of the other entity set through Participation
this relationship type Constraints
l..h Representation
Alternate Mapping
Cardinality Representation
• Total participation: If, in order to exist, every entity must Strong Entity sets and
participate in the relationship, then participation of the Weak Entity sets
6.9
ER Modeling...
l..h Representation
Chittaranjan Pradhan
l..h Representation
An edge between an entity set and a binary relationship set Keys
Keys for Relationship sets
can have an associated minimum and maximum cardinality; Relationship Types
shown as l..h, where l is the minimum and h is the maximum Participation
Constraints
cardinality l..h Representation
Alternate Mapping
Cardinality Representation
• A minimum value of 1 indicates total participation of the Strong Entity sets and
Weak Entity sets
entity set in the relationship set
• A maximum value of 1 indicates that the entity participates
in at most one relationship, while a maximum value *
indicates no limit
• 1..* indicates total participation or double line
6.10
ER Modeling...
Alternate Mapping Cardinality Representation
Chittaranjan Pradhan
Alternate Mapping Cardinality Representation
Keys
Keys for Relationship sets
Relationship Types
Participation
Constraints
l..h Representation
Alternate Mapping
Cardinality Representation
6.11
ER Modeling...
Strong Entity sets and Weak Entity sets
Chittaranjan Pradhan
An entity set where the entities have independent existence Relationship Types
its own unique identifier is known as weak entity set Strong Entity sets and
Weak Entity sets
6.12
ER Modeling...
Strong Entity sets and Weak Entity sets...
Chittaranjan Pradhan
Relationship Types
relationship type uniquely identifies weak entities, is called
Participation
the partial key of the weak entity set and is denoted by a Constraints
dotted underline. The partial key of a weak entity set is l..h Representation
Alternate Mapping
6.13
ER Design Issues
Chittaranjan Pradhan
ER Design
System 7 Methodologies
ER Design Issues
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
7.1
ER Design Issues
ER Design Issues
Chittaranjan Pradhan
ER Design Issues
ER design issues need to be discussed for better ER- design ER Design Issues
ER Design
Methodologies
1. Use of Entity set vs. Attributes
In the real world situations, sometimes it is difficult to select the
property as an attribute or an entity set
7.2
ER Design Issues
ER Design Issues...
Chittaranjan Pradhan
7.3
ER Design Issues
ER Design Issues...
Chittaranjan Pradhan
ER Design
Relationships in databases are often binary. Some Methodologies
7.4
ER Design Issues
ER Design Issues...
Chittaranjan Pradhan
ER Design Issues
ER Design
Methodologies
It is always possible to replace a non-binary relationship set by
a number of distinct binary relationship sets. For example,
consider a ternary relationship R associated with three entity
sets A, B and C. We can replace the relationship set R by an
entity set E and create three relationship sets as:
• RA , relating E and A
• RB , relating E and B
• RC , relating E and C
If the relationship set R had any attributes, these are assigned
to entity set E. A special identifying attribute is created for E
7.5
ER Design Issues
ER Design Issues...
Chittaranjan Pradhan
ER Design Issues
ER Design
4. Placement of Relationship Attributes Methodologies
7.6
ER Design Issues
ER Design Methodologies
Chittaranjan Pradhan
ER Design Issues
7.7
Enhanced ER-Model
Chittaranjan Pradhan
Generalization
System 8 Constraints on
Generalization/Specia-
lization
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
8.1
Enhanced ER-Model
Specialization
Chittaranjan Pradhan
Specialization
Generalization
Specialization
Constraints on
Generalization/Specia-
The process of designating sub groupings within an entity set is lization
8.2
Enhanced ER-Model
Specialization...
Chittaranjan Pradhan
Constraints on
Generalization/Specia-
lization
Aggregation
8.3
Enhanced ER-Model
Generalization
Chittaranjan Pradhan
Generalization Specialization
Constraints on
a containment relationship that exists between a higher-level Generalization/Specia-
lization
entity set and one or more low-level entity sets
Aggregation
8.4
Enhanced ER-Model
Generalization...
Chittaranjan Pradhan
Specialization
Generalization
Constraints on
Generalization/Specia-
lization
Aggregation
8.5
Enhanced ER-Model
Constraints on Generalization/Specialization
Chittaranjan Pradhan
Specialization
Generalization
Constraints on
a. Condition defined or not Generalization/Specia-
lization
8.6
Enhanced ER-Model
Constraints on Generalization/Specialization...
Chittaranjan Pradhan
b. Disjoint or Overlapping
Specialization
Generalization
• Disjoint: A Disjointness constraint requires that an entity
Constraints on
belong to only one lower-level entity set Generalization/Specia-
lization
• Overlapping: In overlapping generalizations, the same Aggregation
entity may belong to more than one lower-level entity set
within a single generalization
• Lower-level entity overlap is the default case. A
disjointness constraint must be placed explicitly on a
generalization. This is done by adding the word disjoint
next to the ISA symbol
8.7
Enhanced ER-Model
Constraints on Generalization/Specialization...
Chittaranjan Pradhan
Specialization
Constraints on
Completeness constraint on a generalization/specialization Generalization/Specia-
lization
specifies whether or not an entity in the higher-level entity set Aggregation
must belong to at least one of the lower-level entity sets within
the generalization/specialization
• Total generalization/specialization: Each higher-level
entity must belong to a lower-level entity set
• Partial generalization/specialization: Some higher-level
entities may not belong to any lower-level entity set
• Partial generalization is the default. Total generalization in
an ER diagram can be specified by using a double line to
connect the box representing the higher-level entity set to
the triangle symbols
8.8
Enhanced ER-Model
Aggregation
Chittaranjan Pradhan
Specialization
Aggregation
Generalization
Aggregation
8.9
Enhanced ER-Model
Aggregation...
Chittaranjan Pradhan
Aggregation
Specialization
8.10
Relational Model
Chittaranjan Pradhan
Relational Database
CODD’s Rules
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
9.1
Relational Model
Relational Model
Chittaranjan Pradhan
• Relational data model is the primary data model for Relational Model
Relational Database
commercial data- processing applications
Relational Data
• A relational database consists of a collection of tables, Integrity
Database Languages
each of which is assigned a unique name
CODD’s Rules
• A row in a table represents a relationship among a set of
values. Thus, a table is an entity set and a row is an entity
• The columns or properties are called attributes
• For each attribute, there is a set of permitted values, called
the domain of that attribute. Same domain can be shared
by more than one attribute
• Degree is the number of attributes in the relation/ table,
where as Cardinality is the number of tuples or rows in the
relation/table
• The attribute values are required to be atomic, i.e.
indivisible
9.2
Relational Model
Relational Model...
Chittaranjan Pradhan
Relational Model
• Let D1 , D2 , and D3 are the domains. Any row of the table
Relational Database
consists of a 3-tuple (v1 , v2 , v3 ) where v1 ∈ D1 , v2 ∈ D2
Relational Data
and v3 ∈ D3 . Thus, the table will contain only a subset of Integrity
the set of all possible rows. Therefore, the table is a subset Database Languages
of D1 x D2 x D3 CODD’s Rules
9.3
Relational Model
Relational Database
Chittaranjan Pradhan
Relational Model
Relational Database
Relational Data
Integrity
Database Languages
Relational Database
CODD’s Rules
Relational database is a database consisting of multiple
relations or tables. The information about an enterprise is
broken up into parts, with each relation storing one part of the
information
9.4
Relational Model
Relational Data Integrity
Chittaranjan Pradhan
Relational Database
uniquely identify a row or tuple in a table. Let R be the relation
Relational Data
with attributes a1 , a2 ... an . The set of attributes of R is said to Integrity
be a candidate key of R iff the following two properties holds: Database Languages
CODD’s Rules
• Uniqueness: At any given time, no two distinct tuples or
rows of R have the same value for ai , the same value for aj
...an
• Minimality: No proper subset of the set (ai , aj ... an ) has
the uniqueness property
2. Entity Integrity
Relational Model
• The entity integrity rule is designed to assure that every Relational Database
Relational Data
relation has a primary key, and that the data values for that Integrity
CODD’s Rules
• Usually, the primary key of each relation is the first column
• Entity integrity guarantees that every primary key attribute
is NOT NULL
• Primary key performs the unique identification function in a
relational model
3. Referential Integrity
9.6
Relational Model
Relational Data Integrity...
Chittaranjan Pradhan
Relational Model
3. Referential Integrity...
Relational Database
Relational Data
• The rule states that if there is a foreign key in one relation, Integrity
either each foreign key value must match a primary key Database Languages
value in the other table or else the foreign key value must CODD’s Rules
be NULL
• A foreign key that references its own relation is known as
recursive foreign key
• The linking between the foreign key and primary key
allows a set of relations to form an integrated database
4. Operational Constraints
9.7
Relational Model
Database Languages
Chittaranjan Pradhan
DDL (Data Definition Language)
Relational Model
• DDL is used to define the conceptual schema. The
Relational Database
definition includes the information of all the entity sets and Relational Data
their associated attributes as well as the relationships Integrity
Database Languages
between the entity sets
CODD’s Rules
• The data values stored in the database must specify
certain consistency constraints. The database systems
check these constraints every time the database is
updated
• The output of the DDL is placed in the Data Dictionary
which contains the metadata (data about data)
• The data dictionary is considered to be a special type of
table, which can only be accessed and updated by the
database system itself
• The database system consults the data dictionary, before
querying or modifying the actual data, for the validation
purpose
• CREATE, ALTER, DROP, RENAME & TRUNCATE
9.8
Relational Model
Database Languages...
Chittaranjan Pradhan
Database Languages
Rule0 CODD’s Rules
NULL values are supported in fully relational DBMS for Relational Database
Relational Data
representing missing information and inapplicable information Integrity
in a systematic way independent of data type Database Languages
CODD’s Rules
9.11
Relational Model
CODD’s Rules...
Chittaranjan Pradhan
Rule6: Views updation
All views that are theoretically updatable are also updatable by Relational Model
the system. Similarly, the views which are theoretically Relational Database
Relational Data
non-updatable are also non-updatable by the database system Integrity
Database Languages
may spread across more than one system and across several Relational Database
Relational Data
networks. However to the end-user, the tables should appear Integrity
CODD’s Rules
Database Management
Conversion of ER
Conversion of ER model to
Relational Model
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
10.1
Conversion of ER
Conversion of ER model to Relational Model model to Relational
Model
Chittaranjan Pradhan
Conversion of ER model to Relational Model
A database that conforms to an ER diagram schema can be Conversion of ER
model to Relational
represented by a collection of relational schemas. Both the ER Model
10.3
Conversion of ER
Conversion of ER model to Relational Model... model to Relational
Model
Chittaranjan Pradhan
3. Representation of Relationship sets
Conversion of ER
model to Relational
3.a. Binary M:N Model
relationship set
10.7
Conversion of ER
Conversion of ER model to Relational Model... model to Relational
Model
Chittaranjan Pradhan
Conversion of ER
model to Relational
Model
5. Representation of Composite attributes
The composite attributes are flattened out by creating a
separate attribute for each of its parts
10.8
Conversion of ER
Conversion of ER model to Relational Model... model to Relational
Model
Chittaranjan Pradhan
Conversion of ER
model to Relational
6. Representation of Multi-valued attributes Model
10.9
Conversion of ER
Conversion of ER model to Relational Model... model to Relational
Model
Chittaranjan Pradhan
7. Representation of Generalization/Specialization
In case of generalization/specialization-related ER diagram, Conversion of ER
model to Relational
one schema will be constructed for the generalized entity set Model
Conversion of ER
model to Relational
Model
Representation of Generalization/Specialization...
When the generalization/specialization is a disjointness case,
the schemas are constructed only for the specialized entity sets
10.11
Conversion of ER
Conversion of ER model to Relational Model... model to Relational
Model
Chittaranjan Pradhan
Relational Algebra
PROJECT
RENAME Operator(ρ)
Union Compatibility
UNION Operator(∪)
DIFFERENCE
Operator(-)
Cartesian Product
Operator(×)
Intersection
Operator(∩)
JOIN Operator(o
n)
Division Operator(÷)
Assignment
Operator(←)
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
11.1
Relational Algebra
Query Language
Chittaranjan Pradhan
Query Language
Relational Algebra
Language in which user requests information from the SELECT Operator(σ)
database are: PROJECT
Operator(π)
• Procedural language Composition of Relational
Operators
Union Compatibility
UNION Operator(∪)
11.2
Relational Algebra
Relational Algebra
Chittaranjan Pradhan
Query Language
Relational Algebra
Relational Algebra
SELECT Operator(σ)
Relational algebra is a procedural language for manipulating PROJECT
Operator(π)
relations. Relational algebra operations manipulate relations. Composition of Relational
Operators
That is, these operations use one or two existing relations to
RENAME Operator(ρ)
create a new relation Union Compatibility
UNION Operator(∪)
• Fundamental operators DIFFERENCE
Operator(-)
• Unary: SELECT, PROJECT, RENAME
Cartesian Product
• Binary: UNION, SET DIFFERENCE, CARTESIAN Operator(×)
PRODUCT Intersection
Operator(∩)
JOIN Operator(o
n)
• Secondary operators Division Operator(÷)
• INTERSECTION, NATURAL JOIN, DIVISION, and Assignment
Operator(←)
ASSIGNMENT
11.3
Relational Algebra
Relational Algebra...
Chittaranjan Pradhan
Query Language
The relational schemas used for different operations are: Relational Algebra
SELECT Operator(σ)
• Customer(cust_name, cust_street, cust_city)
PROJECT
• used to store customer details Operator(π)
Composition of Relational
• Branch(branch_name, branch_city, assets) Operators
RENAME Operator(ρ)
• used to store branch details
Union Compatibility
• Account(acc_no, branch_name, balance) UNION Operator(∪)
• stores the account details DIFFERENCE
Operator(-)
• Loan(loan_no, branch_name, amount) Cartesian Product
Operator(×)
• stores the loan details
Intersection
• Depositor(cust_name, acc_no) Operator(∩)
JOIN Operator(o
n)
• stores the details about the customers’ account
Division Operator(÷)
• Borrower(cust_name, loan_no)
Assignment
• used to store the details about the customers’ loan Operator(←)
11.4
Relational Algebra
SELECT Operator(σ)
Chittaranjan Pradhan
SELECT Operator(σ)
Query Language
SELECT operation is used to create a relation from another
Relational Algebra
relation by selecting only those tuples or rows from the original SELECT Operator(σ)
relation that satisfy a specified condition. It is denoted by sigma PROJECT
(σ) symbol. The predicate appears as a subscript to σ Operator(π)
Composition of Relational
Operators
RENAME Operator(ρ)
The argument relation is in parenthesis after the σ. The result is
Union Compatibility
a relation that has the same attributes as the relation specified UNION Operator(∪)
in <relation-name>. The general syntax of select operator is: DIFFERENCE
σ <selection−condition> (<relation name>) Operator(-)
Cartesian Product
Operator(×)
Query: Find the details of the loans taken from ’Bhubaneswar Intersection
Main’ branch. Operator(∩)
JOIN Operator(o
n)
σ branch_name=0 BhubaneswarMain0 (Loan)
Division Operator(÷)
• The operators used in selection predicate may be: =, 6=, <, Assignment
≤, >, ≥. Operator(←)
Query Language
Relational Algebra
Loan SELECT Operator(σ)
loan_no branch_name amount
PROJECT
L201 Bhubaneswar Main 50,000,000.00 Operator(π)
L202 Bhubaneswar Main 5,000,000.00 Composition of Relational
Operators
L203 Mumbai Main 100,000,000.00 RENAME Operator(ρ)
L204 Juhu 60,000,000.00 Union Compatibility
UNION Operator(∪)
σ branch_name=0 BhubaneswarMain0 (Loan) DIFFERENCE
loan_no branch_name amount Operator(-)
Assignment
L201 Bhubaneswar Main 50,000,000.00 Operator(←)
11.6
Relational Algebra
PROJECT Operator(π)
Chittaranjan Pradhan
Query Language
Relational Algebra
SELECT Operator(σ)
PROJECT Operator(π)
PROJECT
Operator(π)
PROJECT operation can be thought of as eliminating Composition of Relational
RENAME Operator(ρ)
denoted by pie(π) symbol. The attributes needed to be
Union Compatibility
appeared in the resultant relation appear as subscript to π. UNION Operator(∪)
DIFFERENCE
The argument relation follows in parenthesis. The general Operator(-)
Cartesian Product
syntax of project operator is: Operator(×)
JOIN Operator(o
n)
Query: Find the loan numbers and respective loan amounts.
Division Operator(÷)
π loan_no,amount (Loan) Assignment
Operator(←)
11.7
Relational Algebra
PROJECT Operator(π)...
Chittaranjan Pradhan
Query Language
Relational Algebra
SELECT Operator(σ)
Loan PROJECT
loan_no branch_name amount Operator(π)
L201 Bhubaneswar Main 50,000,000.00 Composition of Relational
Operators
L202 Bhubaneswar Main 5,000,000.00 RENAME Operator(ρ)
L203 Mumbai Main 100,000,000.00 Union Compatibility
L204 Juhu 60,000,000.00 UNION Operator(∪)
DIFFERENCE
π loan_no,amount (Loan) Operator(-)
Assignment
Operator(←)
11.8
Relational Algebra
Composition of Relational Operators
Chittaranjan Pradhan
PROJECT
Operator(π)
Q:Find the name of the customers who live in Bhubaneswar Composition of Relational
Operators
RENAME Operator(ρ)
Customer
Union Compatibility
cust_name cust_street cust_city
UNION Operator(∪)
Rishi India Gate New Delhi
DIFFERENCE
Sarthak M. G. Road Bangalore Operator(-)
JOIN Operator(o
n)
Assignment
Operator(←)
cust_name
Manas
Ramesh
11.9
Relational Algebra
RENAME Operator(ρ)
Chittaranjan Pradhan
Relational Algebra
The results of relational algebra expressions do not have a
SELECT Operator(σ)
name that can be used to refer them. It is useful to be able to PROJECT
give them names; the rename operator is used for this Operator(π)
Composition of Relational
purpose. It is denoted by rho(ρ) symbol. Operators
RENAME Operator(ρ)
Union Compatibility
The general syntax of rename operator is:
UNION Operator(∪)
ρ X (E)
DIFFERENCE
Operator(-)
JOIN Operator(o
n)
π cust_name (σ cust_city =0 Bhubaneswar 0 (Customer)) can be written as:
Division Operator(÷)
1. ρ Customer _Bhubaneswar (σ cust_city =0 Bhubaneswar 0 (Customer)) Assignment
Operator(←)
2. π cust_name (Customer_Bhubaneswar)
11.10
Relational Algebra
RENAME Operator(ρ)...
Chittaranjan Pradhan
Query Language
Relational Algebra
The different forms of the rename operation for renaming the SELECT Operator(σ)
relation are: PROJECT
Operator(π)
Composition of Relational
a. ρ S (R) Operators
RENAME Operator(ρ)
Union Compatibility
b. ρ S(b1 ,b2 ,...bn ) (R) UNION Operator(∪)
DIFFERENCE
c. ρ (b1 ,b2 ,...bn ) (R) Operator(-)
Cartesian Product
Operator(×)
Division Operator(÷)
ρ (name,street,city ) (Customer) Assignment
Operator(←)
11.11
Relational Algebra
Union Compatibility
Chittaranjan Pradhan
Query Language
Relational Algebra
SELECT Operator(σ)
Union Compatibility PROJECT
Operator(π)
To perform the set operations such as UNION, DIFFERENCE Composition of Relational
Operators
and INTERSECTION, the relations need to be union RENAME Operator(ρ)
compatible for the result to be a valid relation Union Compatibility
UNION Operator(∪)
Two relations R1 (a1 ,a2 ,... an ) and R2 (b1 ,b2 ,... bm ) are union DIFFERENCE
Operator(-)
compatible iff: Cartesian Product
Operator(×)
Intersection
• n = m, i.e. both relations have same arity Operator(∩)
Division Operator(÷)
Assignment
Operator(←)
11.12
Relational Algebra
UNION Operator(∪)
Chittaranjan Pradhan
UNION Operator(∪)
The union operation is used to combine data from two Query Language
SELECT Operator(σ)
relations R1 (a1 ,a2 ,... an ) and R2 (b1 ,b2 ,... bn ) is a relation R3
PROJECT
(c1 ,c2 ,... cn ) such that: Operator(π)
R1 ∪ R2 is a relation that includes all tuples that are either RENAME Operator(ρ)
UNION Operator(∪)
DIFFERENCE
Depositor Borrower Operator(-)
cust_name acc_no cust_name loan_no Cartesian Product
Manas A101 Ramesh L201 Operator(×)
Assignment
π cust_name (Depositor) ∪ π cust_name (Borrower) Operator(←)
cust_name
Manas
Ramesh
Rishi
Mahesh
11.13
Relational Algebra
DIFFERENCE Operator(-)
Chittaranjan Pradhan
DIFFERENCE Operator(-)
Query Language
The difference operation is used to identify the rows that are in
Relational Algebra
one relation and not in another. It is denoted as (-) symbol. The SELECT Operator(σ)
difference of two relations R1 (a1 ,a2 ,... an ) and R2 (b1 ,b2 ,... bn ) is PROJECT
a relation R3 (c1 ,c2 ,... cn ) such that: Operator(π)
Composition of Relational
dom(ci ) = dom(ai ) - dom(bi ), 1 ≤ i ≤ n Operators
RENAME Operator(ρ)
R1 - R2 is a relation that includes all tuples that are in R1 , but
Union Compatibility
not in R2 UNION Operator(∪)
DIFFERENCE
Operator(-)
Depositor Borrower Cartesian Product
cust_name acc_no cust_name loan_no Operator(×)
Manas A101 Ramesh L201 Intersection
Ramesh A102 Ramesh L202 Operator(∩)
Query Language
Relational Algebra
Cartesian Product Operator(×) SELECT Operator(σ)
The Cartesian product of two relations R1 (a1 ,a2 ,... an ) with PROJECT
Operator(π)
cardinality i and R2 (b1 ,b2 ,... bm ) with cardinality j is a relation Composition of Relational
Operators
R3 with RENAME Operator(ρ)
UNION Operator(∪)
• cardinality i*j and
DIFFERENCE
Operator(-)
• attributes (a1 ,a2 ,... an , b1 ,b2 ,... bm ))
Cartesian Product
R1 × R2 is a relation that includes all the possible combinations Operator(×)
Intersection
of tuples from R1 and R2 . The Cartesian product is used to Operator(∩)
combine information from any two relations JOIN Operator(o
n)
11.15
Relational Algebra
Cartesian Product Operator(×)...
Chittaranjan Pradhan
Borrower Loan
cust_name loan_no loan_no branch_name amount Query Language
11.16
Relational Algebra
Cartesian Product Operator(×)...
Chittaranjan Pradhan
Query Language
Relational Algebra
SELECT Operator(σ)
PROJECT
Query: Find out the customer and their loan details taken from Operator(π)
Composition of Relational
Bhubaneswar Main branch. Operators
RENAME Operator(ρ)
Ans: σ branch_name=0 BhubaneswarMain0 ANDBorrower .loan_no=Loan.loan_no
Union Compatibility
(Borrower ×Loan)
UNION Operator(∪)
DIFFERENCE
Operator(-)
cust_name Borrower.loan_no Loan.loan_no branch_name amount
Cartesian Product
Ramesh L201 L201 Bhubaneswar Main 50,000,000.00 Operator(×)
Ramesh L202 L202 Bhubaneswar Main 5,000,000.00
Intersection
Operator(∩)
JOIN Operator(o
n)
Division Operator(÷)
Assignment
Operator(←)
11.17
Relational Algebra
Intersection Operator(∩)
Chittaranjan Pradhan
Intersection Operator(∩)
The intersection operation is used to identify the rows that are Query Language
SELECT Operator(σ)
intersection of two relations R1 (a1 ,a2 ,... an ) and R2 (b1 ,b2 ,... bn )
PROJECT
is a relation R3 (c1 ,c2 ,... cn ) such that: Operator(π)
R1 ∩ R2 is a relation that includes all tuples that are present in RENAME Operator(ρ)
DIFFERENCE
difference operations as R ∩ S = R - (R - S) Operator(-)
Cartesian Product
Operator(×)
Depositor Borrower
Intersection
cust_name acc_no cust_name loan_no Operator(∩)
Manas A101 Ramesh L201 JOIN Operator(o
n)
Ramesh A102 Ramesh L202
Division Operator(÷)
Rishi A103 Mahesh L203
Assignment
Mahesh A104 Rishi L204 Operator(←)
Mahesh A105
JOIN Operator(o
n)
Query Language
The join is a binary operation that is used to combine certain Relational Algebra
selections and a Cartesian product into one operation. It is SELECT Operator(σ)
Cartesian Product
Query: Find the names of customers who have a loan at the Operator(×)
bank, along with the loan number and the loan amount. Intersection
Operator(∩)
Ans:This query can be solved by using the PROJECT,
JOIN Operator(o
n)
SELECT and CARTESIAN PRODUCT operators as: Division Operator(÷)
π cust_name,Loan.loan_no,amount (σ Borrower .loan_no=Loan.loan_no Assignment
(Borrower ×Loan)) Operator(←)
Query Language
Relational Algebra
SELECT Operator(σ)
Borrower Loan PROJECT
cust_name loan_no loan_no branch_name amount Operator(π)
Ramesh L201 L201 Bhubaneswar Main 50,000,000.00 Composition of Relational
Operators
Ramesh L202 L202 Bhubaneswar Main 5,000,000.00
RENAME Operator(ρ)
Mahesh L203 L203 Mumbai Main 100,000,000.00
Union Compatibility
Rishi L204 L204 Juhu 60,000,000.00
UNION Operator(∪)
DIFFERENCE
π cust_name,loan_no,amount (Borrower o
n Loan)) Operator(-)
Assignment
Operator(←)
11.20
Relational Algebra
Division Operator(÷)
Chittaranjan Pradhan
Division Operator(÷)
Query Language
The division operation creates a new relation by selecting the Relational Algebra
rows in one relation that match every row in another relation. SELECT Operator(σ)
The division operation requires that we look at an entire PROJECT
Operator(π)
relation at once. It is denoted by division (÷) symbol Composition of Relational
Operators
RENAME Operator(ρ)
Let A, B, C are three relations and we desire B ÷ C to give A
Union Compatibility
as the result. This operation is possible iff: UNION Operator(∪)
Intersection
• A row is placed in A if and only if it is associated with B Operator(∩)
Division Operator(÷)
The division operation is the reverse of the Cartesian product Assignment
operation as: B = (B × C) ÷ C Operator(←)
Depositor Account
cust_name acc_no acc_no branch_name balance Query Language
RENAME Operator(ρ)
Intersection
Operator(∩)
Query: Find all the customers who have an account at all the
JOIN Operator(o
n)
branches located in Mumbai Division Operator(÷)
Assignment
π cust_name,branch_name (Depositor o n Account) ÷ π branch_name (σ Operator(←)
Assignment Operator(←)
Query Language
It works like assignment in a programming language. In
Relational Algebra
relational algebra, the assignment operator gives a name to a SELECT Operator(σ)
relation. It is denoted by (←) symbol PROJECT
Assignment must always be made to a temporary relation Operator(π)
Composition of Relational
RENAME Operator(ρ)
the relation variable on the left of the ← symbol
Union Compatibility
With the assignment operator, a query can be written as a UNION Operator(∪)
sequential program consisting of: DIFFERENCE
Operator(-)
• a series of assignment,
Cartesian Product
Operator(×)
• followed by an expression whose value is displayed as a
Intersection
result of the query Operator(∩)
JOIN Operator(o
n)
π n Account) ÷ π branch_name (σ
cust_name,branch_name (Depositor o
Division Operator(÷)
0
branch_city = Mumbai 0 (Branch)) Assignment
Operator(←)
can be simplified as:
Temp1 ← π cust_name,branch_name (Depositor o n Account)
Temp2 ← π branch_name (σ branch_city =0 Mumbai 0 (Branch))
Result = Temp1 ÷ Temp2 11.23
JOIN
Chittaranjan Pradhan
Aggregate
System 12 Functions(g)
Join
Outer Join
Left Outer Join
Right Outer Join
Full Outer Join
Self Join
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
12.1
JOIN
Generalized Projection
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Generalized Projection
Join
The generalized-projection operation extends the projection Inner Join
Outer Join
Left Outer Join
Self Join
Ex:Emp=(ssn, salary, deduction, years_service) be a relation.
A report may be required to show net_salary=salary-deduction,
bonus=2000*years_service and tax=0.25*salary
12.2
JOIN
Aggregate Functions(g)
Chittaranjan Pradhan
Aggregate Functions(g)
Aggregate functions take a collection of values and return a Generalized Projection
Aggregate
single value as a result. NULL value will not participate in the Functions(g)
Outer Join
Query: Find the total sum of salaries of all the employees Left Outer Join
Self Join
Query: Find the total sum of salaries of all the employees in
each branch
Ans: branch_name g SUM(salary ) (Works)
Generalized Projection
Join Aggregate
Functions(g)
Tables are joined on columns that have the same datatype and Inner Join
Theta Join
data width in the tables Equi Join
Natural Join
Outer Join
Join operation joins two relations by merging those tuples from Left Outer Join
Right Outer Join
two relations that satisfy a given condition. The condition is Full Outer Join
12.4
JOIN
Inner Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Join
• Equi Join
• Natural Join
12.5
JOIN
Theta Join(o
n θ)
Chittaranjan Pradhan
Generalized Projection
Theta Join(o
n θ) Aggregate
Functions(g)
Inner Join
column from each relation. This condition specifies that the two Theta Join
Outer Join
The comparison operator can be any of the six: <, ≤, >, ≥, = Left Outer Join
Right Outer Join
and 6= Full Outer Join
Self Join
12.6
JOIN
Theta Join(o
n θ )...
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Account Loan Join
acc_no branch_name balance loan_no branch_name amount
A101 Bhubaneswar Main 100,000.00 L201 Bhubaneswar Main 50,000,000.00 Inner Join
A102 Shastri Nagar 50,000.00 L202 Bhubaneswar Main 5,000,000.00 Theta Join
A103 India Gate 5,000,000.00 L203 Mumbai Main 100,000,000.00 Equi Join
A104 Juhu 600,000.00 L204 Juhu 60,000,000.00 Natural Join
Account o
n balance≥amount Loan
acc_no branch_name balance loan_no branch_name amount
A103 India Gate 5,000,000.00 L202 Bhubaneswar Main 5,000,000.00
A105 Mumbai Main 10,000,000.00 L202 Bhubaneswar Main 5,000,000.00
12.7
JOIN
Equi Join(o
n =)
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Join
Equi Join(o
n =)
Inner Join
Theta Join
The equi join is the theta join based on equality of specified Equi Join
columns. That means the equi join is the special type of theta Natural Join
Outer Join
join where the comparison operator is = Left Outer Join
Right Outer Join
Full Outer Join
The general form of theta join is: Self Join
Ron = S = π all (σ = (R × S))
• Degree (Result) = Degree (R) + Degree (S)
• Cardinality (Result) ≤ Cardinality(R) × Cardinality(S)
12.8
JOIN
Equi Join(o
n = )...
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Borrower Loan Join
cust_name loan_no loan_no branch_name amount
Inner Join
Ramesh L201 L201 Bhubaneswar Main 50,000,000.00 Theta Join
Ramesh L202 L202 Bhubaneswar Main 5,000,000.00 Equi Join
Natural Join
Mahesh L203 L203 Mumbai Main 100,000,000.00
Outer Join
Rishi L204 L204 Juhu 60,000,000.00
Left Outer Join
Right Outer Join
Q: Find the customer name and their loan details Full Outer Join
Self Join
Borrower o
n Borrower .loan_no=Loan.loan_no Loan
cust_name Borrower.loan_no Loan.loan_no branch_name amount
Ramesh L201 L201 Bhubaneswar Main 50,000,000.00
Ramesh L202 L202 Bhubaneswar Main 5,000,000.00
Mahesh L203 L203 Mumbai Main 100,000,000.00
Rishi L204 L204 Juhu 60,000,000.00
12.9
JOIN
Natural Join(o
n)
Chittaranjan Pradhan
Generalized Projection
Natural Join(o
n) Aggregate
Functions(g)
To perform natural join on two relations, they should contain at Join
least one common attributes. It is just like the equi join with the Inner Join
Theta Join
elimination of the common attributes. The natural join is Equi Join
Outer Join
Left Outer Join
12.10
JOIN
Natural Join(o
n)...
Chittaranjan Pradhan
Generalized Projection
Aggregate
Borrower Loan Functions(g)
cust_name loan_no loan_no branch_name amount Join
Ramesh L201 L201 Bhubaneswar Main 50,000,000.00 Inner Join
Ramesh L202 L202 Bhubaneswar Main 5,000,000.00 Theta Join
Equi Join
Mahesh L203 L203 Mumbai Main 100,000,000.00 Natural Join
Rishi L204 L204 Juhu 60,000,000.00 Outer Join
Left Outer Join
Right Outer Join
Q: Find the customer name and their loan details Full Outer Join
Self Join
Borrower o
n Loan
cust_name loan_no branch_name amount
Ramesh L201 Bhubaneswar Main 50,000,000.00
Ramesh L202 Bhubaneswar Main 5,000,000.00
Mahesh L203 Mumbai Main 100,000,000.00
Rishi L204 Juhu 60,000,000.00
12.11
JOIN
Outer Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Outer Join Functions(g)
Inner Join
missing information. The outer join consists of two steps: Theta Join
Equi Join
• First, a natural join is executed Natural Join
• Then if any record in one relation does not match a record Outer Join
Left Outer Join
from the other relation in the natural join, that unmatched Right Outer Join
Full Outer Join
record is added to the join relation, and the additional Self Join
columns are filled with NULLs
The different types of outer join are:
• Left Outer Join
• Right Outer Join
• Full Outer Join
12.12
JOIN
Left Outer Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
./ Inner Join
Theta Join
) Equi Join
Natural Join
The left outer join preserves all tuples in left relation. The left Outer Join
Left Outer Join
outer join is denoted by symbol: Right Outer Join
Full Outer Join
Self Join
./
12.13
JOIN
Left Outer Join...
Chittaranjan Pradhan
Customer Borrower
cust_name cust_street cust_city cust_name loan_no Generalized Projection
Outer Join
Q: Find out the customer details who have taken loans as well Left Outer Join
Self Join
Customer ./ Borrower
cust_name cust_street cust_city loan_no
Rishi India Gate New Delhi L204
Ramesh M. G. Road Bhubaneswar L201
Ramesh M. G. Road Bhubaneswar L202
Mahesh Juhu Mumbai L203
Sarthak M. G. Road Bangalore NULL
Manas Shastri Nagar Bhubaneswar NULL
12.14
JOIN
Right Outer Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
./ Inner Join
Theta Join
) Equi Join
Natural Join
The right outer join preserves all tuples in right relation. The Outer Join
Left Outer Join
right outer join is denoted by symbol: Right Outer Join
Full Outer Join
Self Join
./
12.15
JOIN
Right Outer Join...
Chittaranjan Pradhan
Borrower Customer
cust_name loan_no cust_name cust_street cust_city Generalized Projection
Outer Join
Q: Find out the customer details who have taken loans as well Left Outer Join
Self Join
Borrower ./ Customer
cust_name loan_no cust_street cust_city
Rishi L204 India Gate New Delhi
Ramesh L201 M. G. Road Bhubaneswar
Ramesh L202 M. G. Road Bhubaneswar
Mahesh L203 Juhu Mumbai
Sarthak NULL M. G. Road Bangalore
Manas NULL Shastri Nagar Bhubaneswar
12.16
JOIN
Full Outer Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
./ Inner Join
Theta Join
) Equi Join
Natural Join
The full outer join preserves all tuples in both relations. The full Outer Join
Left Outer Join
outer join is denoted by symbol: Right Outer Join
Full Outer Join
Self Join
./
12.17
JOIN
Self Join
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
Join
Self Join
Inner Join
The self join is similar to the theta join. It joins a relation to itself Theta Join
Equi Join
by a condition. The self join can be viewed as a join of two Natural Join
Thus, the self join creates two alias or copies of the same
relation; then performs the theta join by a condition based on
the attributes of these two copies
12.18
JOIN
Self Join...
Chittaranjan Pradhan
Generalized Projection
Aggregate
Functions(g)
cust_name cust_street cust_city Join
Rishi India Gate New Delhi
Inner Join
Sarthak M. G. Road Bangalore
Customer Manas Shastri Nagar Bhubaneswar
Theta Join
Equi Join
Natural Join
Ramesh M. G. Road Bhubaneswar
Outer Join
Mahesh Juhu Mumbai Left Outer Join
Right Outer Join
Q: Find out the customer details as well as the others’ staying Full Outer Join
Self Join
in the same cust_city
C1 o
n C1.cust_city =C2.cust_city C2
C1.cust_name C1.cust_street C1.cust_city C2.cust_name C2.cust_street C2.cust_city
Manas Shastri Nagar Bhubaneswar Ramesh M. G. Road Bhubaneswar
Ramesh M. G. Road Bhubaneswar Manas Shastri Nagar Bhubaneswar
12.19
Query Using Relationa
Algebra
Chittaranjan Pradhan
System 13
Query Using Relational Algebra
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
13.1
Query Using Relationa
Query Using Relational Algebra Algebra
Chittaranjan Pradhan
13.2
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Query Using
Relational Algebra
13.3
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Sailor Database
Query Using
Sailors(sid, sname, rating, age) Relational Algebra
13.4
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Query Using
Relational Algebra
Query: Find the sailor ids of the sailors who’ve reserved all boats
π sid,bid (Reserves) ÷ π bid (Boats)
13.5
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Query Using
Shipment Database Relational Algebra
Query: Find the names of customers with more than $10 million
in annual revenue
π cust_name (σ annual_revenue>$10million (Customer))
13.6
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
13.7
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
13.8
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Query: List the customers whose shipments have been delivered Query Using
by truck driver Ramesh Relational Algebra
13.9
Query Using Relationa
Query Using Relational Algebra... Algebra
Chittaranjan Pradhan
Query: Find the cities which have received shipments from every
customer
π destination_city ,cust_id (Shipment) ÷ π cust_id (Customer)
13.10
Relational Calculus
Chittaranjan Pradhan
Tuple Relational
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
14.1
Relational Calculus
Relational Calculus
Chittaranjan Pradhan
Relational Calculus
Tuple Relational
Relational Calculus Calculus (TRC)
Safe Expressions
Relational calculus is non-procedural Queries
Domain Relational
Calculus (DRC)
In relational calculus, a query is solved by defining a solution Queries
14.2
Relational Calculus
Tuple Relational Calculus (TRC)
Chittaranjan Pradhan
Relational Calculus
Tuple Relational
Calculus (TRC)
Tuple Relational Calculus (TRC) Safe Expressions
Queries
A tuple variable is a variable that takes on tuples of a particular Domain Relational
relation schema as values Calculus (DRC)
Queries
14.3
Relational Calculus
Tuple Relational Calculus (TRC)...
Chittaranjan Pradhan
Domain Relational
Calculus (DRC)
• R ∈ Rel Queries
• R.a op S.b
• R.a op Constant or Constant op R.a
To represent the join and division of relational algebra by
relational calculus, we need quantifiers such as: existential for
join and universal for division
Relational Calculus
Tuple Relational Calculus (TRC) Tuple Relational
Calculus (TRC)
A formula is recursively defined by using the following rules: Safe Expressions
Queries
14.5
Relational Calculus
Safe Expressions
Chittaranjan Pradhan
Relational Calculus
Tuple Relational
Calculus (TRC)
Safe Expressions Safe Expressions
Queries
14.6
Relational Calculus
Queries
Chittaranjan Pradhan
Sailor Database
Relational Calculus
Sailors(sid, sname, rating, age)
Tuple Relational
Boats(bid, bname, color) Calculus (TRC)
Safe Expressions
Reserves(sid, bid, day) Queries
Domain Relational
Calculus (DRC)
Queries
Query: Find the names & ages of sailors with a rating above 4
{T/∃S ∈ Sailors (S.rating >4 ∧ T.sname=S.sname ∧ T.age=
S.age)}
Query: Find the sailor name, boat id & reservation date for each
reservation
{T/∃R ∈ Reserves ∃S ∈ Sailors (R.sid = S.sid ∧
T.sname=S.sname ∧ T.bid=R.bid ∧ T.day=R.day)}
Query: Find the names of sailors who have reserved boat 111
{T/∃R ∈ Reserves ∃S ∈ Sailors (R.sid = S.sid ∧ R.bid=111 ∧
T.sname=S.sname)}
14.7
Relational Calculus
Queries...
Chittaranjan Pradhan
Relational Calculus
Tuple Relational
Query: Find the names of sailors who have reserved a green boat Calculus (TRC)
Safe Expressions
14.8
Relational Calculus
Queries...
Chittaranjan Pradhan
Relational Calculus
Tuple Relational
Calculus (TRC)
Safe Expressions
Queries
Query: Find the names of sailors who have reserved all boats Domain Relational
Calculus (DRC)
Queries
{T/∃S ∈ Sailors ∀B ∈ Boats(∃R ∈ Reserves (S.sid=R.sid ∧
R.bid= B.bid ∧ T.sname= S.sname))}
14.9
Relational Calculus
Domain Relational Calculus (DRC)
Chittaranjan Pradhan
Relational Calculus
Domain Relational Calculus (DRC)
Tuple Relational
In tuple relational calculus, the variables range over the tuples Calculus (TRC)
Safe Expressions
The domain variables are the ones which range over the
underlying domains instead of over the relations
The result of this query is the set of all tuples <x1 , x2 , ... xn > for
which the formula evaluates to TRUE
14.10
Relational Calculus
Domain Relational Calculus (DRC)...
Chittaranjan Pradhan
Domain Relational
• <x1 , x2 , ... xn > ∈ Rel Calculus (DRC)
Queries
• X op Y
• X op Constant or Constant op X
A formula is recursively defined by using the following rules:
• Any atomic formula
• If p and q are formulae, then ¬p, p ∧ q, p ∨ q, or p ⇒ q are
also formulae
• If p is a formula that contains X as a domain variable, then
∃X(p) and ∀ X(p) are also formulae
The quantifiers ∃ & ∀ are said to bind the domain variable X.
Whereas a variable is said to be free in a formula if the formula
does not contain an occurrence of a quantifier that binds it
14.11
Relational Calculus
Queries
Chittaranjan Pradhan
Sailor Database
Sailors(sid, sname, rating, age) Relational Calculus
Domain Relational
Query: Find all sailors with a rating above 7 Calculus (DRC)
Queries
Query: Find the names of sailors who have reserved a green boat
Relational Calculus
{<N>/∃I, T, A (<I, N, T, A> ∈ Sailors ∧ <I, Br, D> ∈ Reserves ∧ Tuple Relational
Calculus (TRC)
∃<Br, Bn, ’green’> ∈ Boats)} Safe Expressions
Queries
Domain Relational
Calculus (DRC)
Query: Find the names of sailors who have reserved at least 2 Queries
boats
{<N>/∃I, T, A (<I, N, T, A> ∈ Sailors ∧ ∃Br1, Br2, D1, D2(<I, Br1,
D1> ∈ Reserves ∧ <I, Br2, D2> ∈ Reserves ∧ Br1 6= Br2))}
Query: Find the names of sailors who have reserved all boats
{<N>/∃I, T, A(<I, N, T, A> ∈ Sailors ∧ ∀<B, Bn, C> ∈ Boats
(∃<Ir, Br, D> ∈ Reserves ( I=Ir ∧ Br=B)))}
14.13
Database Design
Chittaranjan Pradhan
Bad Database
System 15 Design/Concept of
Anomalies
Functional
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
15.1
Database Design
Database Design
Chittaranjan Pradhan
Database Design
Database Design
• First characterize fully the data requirements of the Bad Database
prospective database users, which usually involves in Design/Concept of
Anomalies
textual descriptions Functional
Dependency(FD)
• Next, choose ER model to translate these requirements Trivial FDs and Non-Trivial
FDs
into a conceptual schema of the database Armstrong’s Inference
Axioms
• In the logical design phase, map the high level conceptual Logical Implication
Closure of a Set of
schema onto the implementation data model of the Functional Dependencies
Closure of a Set of
database system that will be used. The implementation Attributes
Redundancy of FDs
Bad Database
It is the anomaly in which the user cannot insert a fact about an Design/Concept of
Anomalies
entity until he/she has an additional fact about another entity. In Functional
other words, there are circumstances in which certain facts can Dependency(FD)
Trivial FDs and Non-Trivial
not be recorded at all. FDs
Armstrong’s Inference
Axioms
Logical Implication
Ex: We cannot record a new prof details without assigning a Closure of a Set of
Functional Dependencies
15.4
Database Design
Bad Database Design/Concept of Anomalies...
Chittaranjan Pradhan
Database Design
Bad Database
Design/Concept of
Anomalies
Updation Anomaly
Functional
Dependency(FD)
It is the anomaly in which the modification in the value of Trivial FDs and Non-Trivial
that value occurs. In other words, the same data can be Axioms
Logical Implication
single row only, then the updation process will put the database
in an inconsistent state so that the phone_no of Mahesh will
give conflicting answers
15.5
Database Design
Functional Dependency(FD)
Chittaranjan Pradhan
Bad Database
Functional Dependency is the building block of normalization Design/Concept of
Anomalies
principles
Functional
Dependency(FD)
Trivial FDs and Non-Trivial
Attribute(s) A in a relation schema R functionally determines FDs
Armstrong’s Inference
another attribute(s) B in R if for a given value a1 of A; there is a Axioms
Logical Implication
single, specific value b1 of B in relation r of R Closure of a Set of
Functional Dependencies
Closure of a Set of
Attributes
The symbolic expression of this FD is: Redundancy of FDs
15.6
Database Design
Functional Dependency(FD)...
Chittaranjan Pradhan
Database Design
Functional Dependency(FD) Bad Database
Design/Concept of
From Student schema, we can infer that Name→Phone_no Anomalies
Functional
because all tuples of Student with a given Name value also Dependency(FD)
have the same Phone_no value Trivial FDs and Non-Trivial
FDs
Armstrong’s Inference
Axioms
Likewise, it can also be inferred that Prof→Grade. At the same Logical Implication
Closure of a Set of
time, notice that Grade does not determine Prof Functional Dependencies
Closure of a Set of
Attributes
Redundancy of FDs
15.7
Database Design
Trivial FDs and Non-Trivial FDs
Chittaranjan Pradhan
Trivial FDs
Database Design
A functional dependency X→Y is a trivial functional Bad Database
dependency if Y is a subset of X Design/Concept of
Anomalies
Functional
For example, {Name, Course}→Course. If two records have the Dependency(FD)
Trivial FDs and Non-Trivial
same values on both the Name and Course attributes, then FDs
Armstrong’s Inference
Functional
Dependency(FD)
Let R(X, Y, Z, W) where X, Y, Z, and W are arbitrary subsets of Trivial FDs and Non-Trivial
FDs
the set of attributes of a universal relation schema R Armstrong’s Inference
Axioms
Logical Implication
Closure of a Set of
The three fundamental inference rules are: Functional Dependencies
Closure of a Set of
• Reflexivity Rule: If Y is a subset of X, then X→Y (Trivial Attributes
Redundancy of FDs
15.9
Database Design
Armstrong’s Inference Axioms...
Chittaranjan Pradhan
Database Design
F|=A→D
15.11
Database Design
Closure of a Set of Functional Dependencies
Chittaranjan Pradhan
Database Design
15.13
Database Design
Closure of a Set of Attributes
Chittaranjan Pradhan
{A}+ = {A, C}, {B}+ = {B, D}, {C}+ ={C}, {D}+ ={D},
{A, B}+ = {A, B, C, D}, {A, C}+ = {A, C}, {A, D}+ = {A, C, D},
{B, C}+ = {B, C, D}, {B, D}+ = {B, D}, {C, D}+ = {C, D},
{A, B, C}+ = {A, B, C, D}, {A, B, D}+ = {A, B, C, D},
{B, C, D}+ = {B, C, D}, {A, B, C, D}+ = {A, B, C, D}
Database Design
Bad Database
Design/Concept of
Anomalies
Uses of Attribute Closure:
Functional
Dependency(FD)
• Testing for key: To test whether X is a key or not, X + is Trivial FDs and Non-Trivial
FDs
X+ Canonical Cover/Minimal
Cover
15.15
Database Design
Redundancy of FDs
Chittaranjan Pradhan
Redundancy of FDs
Given a set of functional dependencies F, a functional Database Design
Functional
FDs F - {A→B} Dependency(FD)
Eliminating redundant functional dependencies allows us to Trivial FDs and Non-Trivial
FDs
redundant
Ex: F= {A→B, B→C, A→{C, D}} can be simplified to {A→B,
B→C, A→D}
Bad Database
For a given set F of FDs, a canonical cover, denoted by Fc , is a Design/Concept of
Anomalies
set of FDs where the following conditions are satisfied: Functional
Dependency(FD)
• F and Fc are equivalent Trivial FDs and Non-Trivial
FDs
• Every FD of Fc is simple. That is, the RHS of every Armstrong’s Inference
Axioms
functional dependency of Fc has only one attribute Logical Implication
Closure of a Set of
Fc = {A→B, B→C}
15.17
Normalization
Chittaranjan Pradhan
Guidelines followed in
Designing Good
Database
Normalization
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
16.1
Normalization
Normalization
Chittaranjan Pradhan
Normalization
Normalization
Normalization is the process of decomposing or breaking a Lossless Decomposition
Guidelines followed in
R2 , ... Rn such that the following conditions hold: Designing Good
Database
• Lossless decomposition: The fragments should contain
the same information as the original relation
• Dependency preservation: All the functional
dependencies should be preserved within each fragment
Ri
• Good form: Each fragment Ri should be free from any
type of redundancy
In other words, normalization is the process of refining the
relational data model. It is used because of the following
reasons:
• It improves database design
• It ensures minimum redundancy of data
• It removes anomalies for database activities
16.2
Normalization
Lossless Decomposition
Chittaranjan Pradhan
Lossless Decomposition
The decomposition of a base relation is said to be lossless if Normalization
Lossless Decomposition
the original relation can be recovered back by joining the Dependency Preservation
A B
R1 R2 a 1
b 2
A B
a 1
R1 o
n R2 a 2
b 1
b 2
As R1 o
n R2 = R, the decomposition is lossless 16.3
Normalization
Lossless Decomposition...
Chittaranjan Pradhan
Normalization
A B Lossless Decomposition
a 1
R a 2
Dependency Preservation
Guidelines followed in
b 1 Designing Good
Database
A
R1 a
b
B
R2 1
2
A B
a 1
R1 o
n R2 a 2
b 1
b 2
16.4
Normalization
Lossless Decomposition...
Chittaranjan Pradhan
Lossless Decomposition...
When the base relation schema is decomposed into the Normalization
Lossless Decomposition
fragmented relation schemas, the consecutive relations should Dependency Preservation
be related by primary key - foreign key pair on the common Guidelines followed in
Designing Good
column; so that natural join be possible on the common Database
(∪i Fi )+ = F +
A B C
1 2 3
R 2 2 3
3 2 3
4 3 4
Key=A
16.6
Normalization
Dependency Preservation...
Chittaranjan Pradhan
Normalization
Lossless Decomposition
A B Dependency Preservation
1 2
Guidelines followed in
R1 = (A, B) and F={A→B} 2 2 Designing Good
3 2 Database
4 3
A C
1 3
R2 = (A, C) and F={A→C} 2 3
3 3
4 4
16.7
Normalization
Dependency Preservation...
Chittaranjan Pradhan
Normalization
Lossless Decomposition
Dependency Preservation
A B
Guidelines followed in
1 2 Designing Good
R1 = (A, B) and F={A→B} 2 2 Database
3 2
4 3
B C
R2 = (B, C) and F={B→C} 2 3
3 4
Thus, (F1 ∪ F2 )+ = F +
16.8
Normalization
Guidelines followed in Designing Good Database
Chittaranjan Pradhan
Guideline 1
Normalization
Design a relation schema so that it is easy to explain its Lossless Decomposition
Dependency Preservation
meaning. Do not combine attributes from multiple entity sets Guidelines followed in
and relationship sets into a single relation Designing Good
Database
Guideline 2
Design the base relation schemas in such a way that the Normalization
Lossless Decomposition
anomalies such as insertion, deletion, or updation anomalies Dependency Preservation
If any anomalies are present, note them clearly and make sure
that the programs that modify (update) the database will
operate correctly
Guideline 3
Avoid placing attributes in a base relation whose values may
frequently be NULL
Normalization
Lossless Decomposition
Dependency Preservation
Guidelines followed in
Designing Good
Database
Guideline 4
Design the relation schemas so that they can be joined in a
such a way that no spurious tuples are generated
16.11
Normal Forms
Chittaranjan Pradhan
1NF(First Normal
System 17 Form)
Partial FD
Transitive FD
3NF(Third Normal
Form)
BCNF (Boyce-Codd
Normal Form)
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
17.1
Normal Forms
Normal Forms
Chittaranjan Pradhan
Normal Forms
1NF(First Normal
Form)
Partial FD
2NF(Second Normal
Normal Forms Form)
Transitive FD
• Normal forms provide a stepwise progression towards the
3NF(Third Normal
construction of normalized relation schemas, which are Form)
17.2
Normal Forms
1NF(First Normal Form)
Chittaranjan Pradhan
Normal Forms
1NF(First Normal Form) 1NF(First Normal
Form)
A relation is in 1NF iff the values in the relation are atomic and Partial FD
Transitive FD
Module Dept Lecturer Text 3NF(Third Normal
M1 D1 L1 T1 ,T2 Form)
17.3
Normal Forms
1NF(First Normal Form)...
Chittaranjan Pradhan
Module Dept Lecturer Text
M1 D1 L1 T1
Normal Forms
M1 D1 L1 T2
1NF(First Normal
M2 D1 L1 T1 Form)
Course1 M2 D1 L1 T3 Partial FD
M3 D1 L2 T4 2NF(Second Normal
Form)
M4 D2 L3 T1
Transitive FD
M4 D2 L3 T5
3NF(Third Normal
M5 D2 L4 T6 Form)
BCNF (Boyce-Codd
Module Dept Lecturer Text1 Text2 Normal Form)
M1 D1 L1 T1 T2
M2 D1 L1 T1 T3
Course2
M3 D1 L2 T4
M4 D2 L3 T1 T5
M5 D2 L4 T6
Normal Forms
1NF(First Normal
Form)
Partial FD
Partial FD 2NF(Second Normal
Form)
A FD A → B is a partial FD, if some attribute of A can be Transitive FD
removed and the FD still holds. That means there is some 3NF(Third Normal
proper subset of A, C ⊂ A, such that C → B Form)
BCNF (Boyce-Codd
Normal Form)
17.5
Normal Forms
2NF(Second Normal Form)
Chittaranjan Pradhan
2NF(Second Normal Form)
A relation is in 2NF iff the following two conditions are met Normal Forms
• It is in 1NF Partial FD
2NF(Second Normal
• No non-key attribute is partially dependent on any key Form)
Transitive FD
Normal Forms
1NF(First Normal
Form)
M1 D1 L1 T1 2NF(Second Normal
Form)
M1 D1 L1 T2
Transitive FD
M2 D1 L1 T1
3NF(Third Normal
Course M2 D1 L1 T3 Form)
M3 D1 L2 T4 BCNF (Boyce-Codd
Normal Form)
M4 D2 L3 T1
M4 D2 L3 T5
M5 D2 L4 T6
17.7
Normal Forms
2NF(Second Normal Form)...
Chittaranjan Pradhan
Normal Forms
3NF(Third Normal
F1 ={Module→{Dept, Lecturer}, Lecturer→Dept} Form)
BCNF (Boyce-Codd
Module Text Normal Form)
M1 T1
M1 T2
M2 T1
Course2 M2 T3
M3 T4
M4 T1
M4 T5
M5 T6
17.8
Normal Forms
2NF(Second Normal Form)...
Chittaranjan Pradhan
Normal Forms
1NF(First Normal
Form)
Corollary: If the primary key has a single attribute, then the Partial FD
relation is in 2NF 2NF(Second Normal
Form)
Transitive FD
Anomalies in 2NF Relations:
3NF(Third Normal
• Insertion anomalies Form)
BCNF (Boyce-Codd
• Updation anomalies Normal Form)
• Deletion anomalies
Q: R=(A, B, C, D, E), & F={A → {B, C, D, E}, {A, B} → {C, D, E},
C → E, D → E}
17.9
Normal Forms
Transitive FD
Chittaranjan Pradhan
Normal Forms
1NF(First Normal
Form)
Partial FD
2NF(Second Normal
Form)
Transitive FD Transitive FD
3NF(Third Normal
A FD A → C is a transitive FD, if there are some set of Form)
17.10
Normal Forms
3NF(Third Normal Form)
Chittaranjan Pradhan
A relation is in 3NF iff the following two conditions are satisfied 1NF(First Normal
Form)
simultaneously:
Partial FD
• It is in 2NF 2NF(Second Normal
Form)
• No non-key attribute is transitively dependent on the key Transitive FD
The process of decomposing the non-3NF relation into 3NF 3NF(Third Normal
Form)
relations is similar to the process of decomposing the non-2NF BCNF (Boyce-Codd
relation to 2NF relations Normal Form)
Normal Forms
1NF(First Normal
Module Lecturer Form)
M1 L1
M2 L1 Partial FD
Course1 M3 L2 2NF(Second Normal
M4 L3 Form)
M5 L4
Transitive FD
3NF(Third Normal
F1 ={Module→Lecturer} Form)
BCNF (Boyce-Codd
Lecturer Dept Normal Form)
L1 D1
Course2 L2 D1
L3 D2
L4 D2
F2 ={Lecturer→Dept}
17.12
Normal Forms
3NF(Third Normal Form)...
Chittaranjan Pradhan
The 3NF helped us to get rid of the anomalies caused by
dependencies of a non-key attribute on another non-key
Normal Forms
attribute
1NF(First Normal
Form)
when the relations have two overlapping candidate keys or 2NF(Second Normal
Form)
when non-key attribute functionally determines a key attribute. Transitive FD
• It is in 3NF Partial FD
2NF(Second Normal
• If for every non-trivial functional dependency, the Form)
3NF(Third Normal
The process of decomposing the non-BCNF relation into BCNF Form)
relations is a simple process. For each non-trivial FD where the BCNF (Boyce-Codd
Normal Form)
determinant is not the key, construct new relations
Normal Forms
1NF(First Normal
Form)
This relation is not present in BCNF as in FD Time → Course; Partial FD
the determinant {Time} is not a key 2NF(Second Normal
Form)
Transitive FD
After the conversion of this relation to BCNF, create a new
3NF(Third Normal
relation R1 =(Time, Course) with set of FDs F1 ={Time → Form)
17.15
Normal Forms
BCNF (Boyce-Codd Normal Form)...
Chittaranjan Pradhan
Corollary: If a relation has only one candidate key, then
3NF and BCNF are same. That means if a relation is in 3NF
Normal Forms
having only one candidate key, then it is also present in
1NF(First Normal
BCNF Form)
Partial FD
lossless, but may not preserve all the functional 3NF(Third Normal
Form)
dependencies
BCNF (Boyce-Codd
Normal Form)
5NF(Fifth Normal
Form)
Denormalization
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
18.1
Advanced Normal
MVD(Multi-Valued Dependency) Forms
Chittaranjan Pradhan
MVD(Multi-Valued
Dependency)
Denormalization
18.2
Advanced Normal
MVD(Multi-Valued Dependency)... Forms
Chittaranjan Pradhan
An MVD that satisfies neither the first nor the second condition
is called a nontrivial MVD
JD(Join Dependency)
• It contains no multiple MVDs
5NF(Fifth Normal
Form)
In other words, a relation is in 4NF iff:
Denormalization
• There are no nontrivial MVDs in the relation, or
• The determinant of any nontrivial MVD in the relation is a
key
Name Hobby
Asis Reading
Employee_Hobby Asis Music Name →→ Hobby
Bikash Riding
Bikash Movies
These relations are present in 4NF because the MVDs are 18.4
Advanced Normal
JD(Join Dependency) Forms
Chittaranjan Pradhan
MVD(Multi-Valued
Dependency)
4NF(Fourth Normal
Form)
JD(Join Dependency) JD(Join Dependency)
18.5
Advanced Normal
5NF(Fifth Normal Form) Forms
Chittaranjan Pradhan
5NF(Fifth Normal Form)
A relation is in 5NF iff the following two conditions are satisfied MVD(Multi-Valued
Dependency)
simultaneously:
4NF(Fourth Normal
• It is in 4NF Form)
JD(Join Dependency)
• Every join dependency is implied by the candidate keys
5NF(Fifth Normal
Form)
In other words, a relation is in 5NF if it is in 4NF and the
Denormalization
decomposition is lossless type
Dealer Parts Customer
D1 P1 C1
Dealer D1 P1 C2
D1 P2 C1
D2 P1 C1
Dealer Parts
MVD(Multi-Valued
D1 P1 Dependency)
Dealer_Parts Dealer →→ Parts
D1 P2 4NF(Fourth Normal
Form)
D2 P1 JD(Join Dependency)
5NF(Fifth Normal
Dealer Customer Form)
D1 C1 Denormalization
Dealer_Customer Dealer →→ Customer
D1 C2
D2 C1
Parts Customer
P1 C1
Parts_Customer Parts →→ Customer
P1 C2
P2 C1
Dealer_Parts o
n Parts_Customer o
n Dealer_Customer = Dealer
MVD(Multi-Valued
Dependency)
JD(Join Dependency)
• Advantages of normalization:
5NF(Fifth Normal
• It removes data redundancy Form)
18.8
Advanced Normal
Denormalization... Forms
Chittaranjan Pradhan
MVD(Multi-Valued
Dependency)
Once a normalized database design has been achieved,
4NF(Fourth Normal
adjustments can be made with the potential consequences Form)
5NF(Fifth Normal
Form)
Possible denormalization steps include the following: Denormalization
18.9
Transactions
Chittaranjan Pradhan
ACID Properties
Transactions
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
19.1
Transactions
Transaction Concept
Chittaranjan Pradhan
Transaction Concept
A transaction is a unit of program execution that accesses and Transaction Concept
Transaction States
19.2
Transactions
ACID Properties
Chittaranjan Pradhan
ACID Properties
Transaction Concept
• Atomicity: Either all operations of the transaction are ACID Properties
reflected properly in the database, or none are. Atomicity Transaction States
Transaction Concept
ACID Properties... ACID Properties
Transaction States
• Durability: After a transaction completes successfully, the
changes it has made to the database persist, even if there
are system failures. Durability ensures that once
transaction changes are done or committed, they can’t be
undone or lost, even in the event of a system failure
19.4
Transactions
ACID Properties...
Chittaranjan Pradhan
T1 Transaction States
Read(A);
A:=A-100;
Write(A);
Read(B);
B:=B+100;
Write(B);
19.5
Transactions
ACID Properties...
Chittaranjan Pradhan
2. Consistency: Sum of A and B be unchanged by the
execution of the transaction
Transaction Concept
• Ensuring the consistency for an individual transaction is
ACID Properties
the responsibility of the application programmers who Transaction States
codes the transaction
3. Isolation: The database is temporarily inconsistent while the
transaction to transfer funds from account A to B is executing.
The solutions are:
• Execute transactions serially
• However, concurrent execution of transactions provides
significant performance benefits such as increased
throughputs
• Ensuring the isolation property is the responsibility of
concurrency control component of the database system
4. Durability: Once a transaction completes successfully, all
the updates that is carried out on the database persist, even if
there is a system failure after the transaction completes
execution
• Ensuring durability is the responsibility of recovery
management component of the database system 19.6
Transactions
Transaction States
Chittaranjan Pradhan
• Active state: This state is the initial state of a transaction.
The transaction stays in this state while it is executing Transaction Concept
ACID Properties
Transaction Concept
ACID Properties
Transaction States
Chittaranjan Pradhan
Schedules
Serializability
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
20.1
Concurrent Execution
Concurrent Execution
Chittaranjan Pradhan
Concurrent Execution
Concurrent Execution
Schedules
Concurrent execution of transactions means executing more Serial Schedule
Concurrent Schedule
than one transaction at the same time Serializability
Conflict Serializability
Testing for Conflict
In the serial execution, one transaction can start executing only Serializability
View Serializability
after the completion of the previous
20.2
Concurrent Execution
Concurrent Execution...
Chittaranjan Pradhan
Concurrent Execution
T1 transfers Dollar $100 from account A to account B Schedules
T1 Serial Schedule
Concurrent Schedule
Read(A);
Serializability
A:=A-100; Conflict Serializability
B:=B+100;
Write(B);
20.3
Concurrent Execution
Schedules
Chittaranjan Pradhan
Concurrent Execution
Schedules
Serial Schedule
Concurrent Schedule
Schedules Serializability
Conflict Serializability
A schedule is a sequence that indicates the chronological order Testing for Conflict
Serializability
20.4
Concurrent Execution
Serial Schedule
Chittaranjan Pradhan
Concurrent Execution
Schedules
Serial Schedule
Concurrent Schedule
Serial Schedule Serializability
Conflict Serializability
A serial schedule is a schedule where all the instructions Testing for Conflict
Serializability
belonging to each transaction appear together View Serializability
20.5
Concurrent Execution
Serial Schedule...
Chittaranjan Pradhan
T1 T2
Read(A);
A:=A-100; Concurrent Execution
Write(A); Schedules
Read(B); Serial Schedule
B:=B+100; Concurrent Schedule
Write(B);
Schedule1 (T1 followed by T2 ) Read(A);
Serializability
Conflict Serializability
Temp=0.2*A; Testing for Conflict
Serializability
A:=A-Temp;
View Serializability
Write(A);
Read(B);
B:=B+Temp;
Write(B);
T1 T2
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Read(B);
B:=B+Temp;
Schedule2 (T2 followed by T1 ) Write(B);
Read(A);
A:=A-100;
Write(A);
Read(B);
B:=B+100;
Write(B);
20.6
Concurrent Execution
Concurrent Schedule
Chittaranjan Pradhan
Schedules
In concurrent schedule, operations from different concurrent Serial Schedule
Serializability
Conflict Serializability
The number of possible schedules for a set of n transactions is Testing for Conflict
Serializability
T1 T2
Read(A);
A:=A-100;
Write(A);
Read(A);
Temp=0.2*A;
A:=A-Temp;
Schedule3 Write(A);
Read(B);
B:=B+100;
Write(B);
Read(B);
B:=B+Temp;
Write(B);
20.7
Concurrent Execution
Concurrent Schedule...
Chittaranjan Pradhan
T1 T2
Read(A);
A:=A-100; Concurrent Execution
Read(A); Schedules
Temp=0.2*A; Serial Schedule
A:=A-Temp; Concurrent Schedule
Write(A);
Schedule4 Read(B);
Serializability
Conflict Serializability
Write(A); Testing for Conflict
Serializability
Read(B);
View Serializability
B:=B+100;
Write(B);
B:=B+Temp;
Write(B);
T1 T2
Read(A);
A:=A-100;
Write(A);
Read(A);
Temp=0.2*A;
A:=A-Temp;
Schedule5 Read(B);
B:=B+100;
Write(A);
Read(B);
B:=B+Temp;
Write(B);
Write(B);
20.8
Concurrent Execution
Serializability
Chittaranjan Pradhan
Concurrent Execution
Serializability Schedules
Serial Schedule
Serializability
serial schedule Conflict Serializability
Testing for Conflict
Serializability
20.9
Concurrent Execution
Serializability...
Chittaranjan Pradhan
Concurrent Execution
T1 T2 T1 T2
Read(A); Read(A); Schedules
Serial Schedule
Write(A); Write(A); Concurrent Schedule
Read(B); Read(B);
Serializability
Write(B); Write(B); Conflict Serializability
Read(A); Read(A); Testing for Conflict
Write(A); Write(A); Serializability
View Serializability
Read(B); Read(B);
Write(B); Write(B);
Schedule1 Schedule2
T1 T2 T1 T2 T1 T2
Read(A); Read(A); Read(A);
Write(A); Read(A); Write(A);
Read(A); Write(A); Read(A);
Write(A); Read(B); Read(B);
Read(B); Write(A); Write(A);
Write(B); Read(B); Read(B);
Read(B); Write(B) Write(B);
Write(B); Write(B); Write(B);
Schedule3 Schedule4 Schedule5
20.10
Concurrent Execution
Conflict Serializability
Chittaranjan Pradhan
Conflict Serializability
Concurrent Execution
Conflict Serializability consists of conflicting operations
Schedules
Let us consider a schedule S in which there are two Serial Schedule
Serializability
respectively (i6=j) Conflict Serializability
Testing for Conflict
Serializability
If Ii and Ij access different data items, then we can swap Ii and View Serializability
Concurrent Execution
Thus, Ii and Ij conflict if they are the instructions by different Schedules
transactions on the same data item, and at least one of these Serial Schedule
Concurrent Schedule
20.12
Concurrent Execution
Conflict Serializability...
Chittaranjan Pradhan
Concurrent Execution
Schedules
Serial Schedule
Concurrent Schedule
Serializability
Conflict Serializability
T1 T2 T1 T2 T1 T2 Testing for Conflict
Serializability
Read(A); Read(A); Read(A); View Serializability
Write(A); Read(A); Write(A);
Read(B); Write(A); Read(B);
Write(B); Write(A); Read(A);
Read(A); Read(B); Write(A);
Write(A); Read(B); Read(B);
Read(B); Write(B) Write(B);
Write(B); Write(B); Write(B);
Schedule3 Schedule4 Schedule5
20.13
Concurrent Execution
Conflict Serializability...
Chittaranjan Pradhan
It is possible to have two schedules that produce the same
outcome, but that are not conflict equivalent
Concurrent Execution
T1 T5
Schedules
Read(A); Serial Schedule
A:=A-100; Concurrent Schedule
Write(A); Serializability
Read(B); Conflict Serializability
B:=B-200; Testing for Conflict
Serializability
Write(B);
View Serializability
Read(B);
B:=B+100;
Write(B);
Read(A);
A:=A+200;
Write(A);
Schedule6
T1 T5
Read(A);
Write(A);
Read(B);
Write(B);
Read(B);
Write(B);
Read(A);
Write(A);
Schedule6
20.14
Concurrent Execution
Testing for Conflict Serializability
Chittaranjan Pradhan
Schedules
Construct a directed graph, called a precedence graph from S. Serial Schedule
Concurrent Schedule
This graph consists of a pair G = (V, E), where V is a set of Serializability
vertices and E is a set of edges Conflict Serializability
Testing for Conflict
Serializability
View Serializability
The set of vertices consists of all the transactions participating
in the schedule
20.15
Concurrent Execution
Testing for Conflict Serializability...
Chittaranjan Pradhan
If the precedence graph for a concurrent schedule S has a
cycle, then that schedule is not conflict serializable. If the
Concurrent Execution
graph contains no cycles, then the schedule S is conflict
Schedules
serializable Serial Schedule
Concurrent Schedule
Serializability
Conflict Serializability
Testing for Conflict
Serializability
View Serializability
20.16
Concurrent Execution
View Serializability
Chittaranjan Pradhan
View Serializability
Concurrent Execution
Concurrent Execution
Schedules
T1 T2 T3 Serial Schedule
Concurrent Schedule
Read(Q);
Serializability
Schedule7 Write(Q); Conflict Serializability
Write(Q); Testing for Conflict
Serializability
Write(Q); View Serializability
20.18
Concurrency Control
Chittaranjan Pradhan
Chittaranjan Pradhan
School of Computer Engineering,
KIIT University
21.1
Concurrency Control
Need of Concurrency Control
Chittaranjan Pradhan
Need of Concurrency
Lost Update Problem Control
Lock-Based Protocols
This problem occurs when two transactions that access the Basic Rules for Locking
Working of Locking
same database items have their operations interleaved in a
Locking Protocol
way that makes the value of some database item incorrect
T1 T2
Read(A);
A:=A-100;
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Write(A);
Read(B);
B:=B+100;
Write(B);
21.2
Concurrency Control
Need of Concurrency Control...
Chittaranjan Pradhan
Need of Concurrency
Temporary Update(or Dirty Read) Problem Control
Lock-Based Protocols
This problem occurs when one transaction updates a database Basic Rules for Locking
Working of Locking
item and then the transaction fails due to some reason. The
Locking Protocol
updated item is accessed by another transaction before it is
changed back to its original value
T1 T2
Read(A);
A:=A-100;
Write(A);
Read(A);
Temp=0.2*A;
A:=A-Temp;
Write(A);
Read(B);
B:=B+100;
21.3
Concurrency Control
Need of Concurrency Control...
Chittaranjan Pradhan
T1 T2
sum=0;
Read(A);
A:=A-100;
Write(A);
Read(A);
sum:=sum+A;
Read(B);
sum:=sum+B;
Read(B);
B:=B+100;
Write(B);
21.4
Concurrency Control
Lock-Based Protocols
Chittaranjan Pradhan
Lock-Based Protocols
Need of Concurrency
Locking is a procedure used to control concurrent access to Control
Working of Locking
Need of Concurrency
Control
• All transactions that need to access a data item must first Lock-Based Protocols
acquire a read lock or write lock on the data item Basic Rules for Locking
Working of Locking
depending on whether it is a read only operation or not Locking Protocol
21.7
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
21.8
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
T1 T2
Read(A);
Need of Concurrency
Write(A); Control
Read(A); Lock-Based Protocols
Schedule3 Write(A); Basic Rules for Locking
Working of Locking
Read(B);
Write(B); Locking Protocol
Read(B);
Write(B);
T1 T2 Concurrency-Control Manager
Lock-X(A)
Grant-X(A, T1 )
Read(A);
Write(A);
Unlock(A)
Lock-X(A)
Grant-X(A, T2 )
Read(A);
Write(A);
Unlock(A)
Lock-X(B)
Grant-X(B, T1 )
Read(B);
Write(B);
Unlock(B)
Lock-X(B)
Grant-X(B, T2 )
Read(B);
Write(B);
Unlock(B)
21.9
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
Need of Concurrency
Control
Lock-Based Protocols
T1 T2 Basic Rules for Locking
Working of Locking
Read(A);
Locking Protocol
Read(A);
Write(A);
Schedule4 Read(B);
Write(A);
Read(B);
Write(B);
Write(B);
T1 T2 Concurrency-Control Manager
Lock-X(A)
Grant-X(A, T1 )
Read(A);
Lock-X(A)
21.10
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
T1 T2
Need of Concurrency
Read(A); Control
Write(A);
Lock-Based Protocols
Read(A); Basic Rules for Locking
Schedule5 Read(B); Working of Locking
T1 T2 Concurrency-Control Manager
Lock-X(A)
Grant-X(A, T1 )
Read(A);
Write(A);
Unlock(A)
Lock-X(A)
Grant-X(A, T2 )
Read(A);
Lock-X(B)
Grant-X(B, T1 )
Read(B);
Write(A);
Unlock(A)
Lock-X(B)
21.11
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
Need of Concurrency
Control
T1 T2
Read(A); Read(A); Lock-Based Protocols
A:=A-100; Read(B); Basic Rules for Locking
T1 T2
Lock-X(A); Lock-S(A);
Read(A); Read(A);
A:=A-100; Unlock(A);
Write(A); Lock-S(B);
Unlock(A); Read(B);
Lock-X(B); Unlock(B);
Read(B); Display(A+B);
B:=B+100;
Write(B);
Unlock(B);
21.12
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
21.13
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
Lock-Based Protocols
unlocking process. That means the unlocking is delayed to the Basic Rules for Locking
Locking Protocol
21.14
Concurrency Control
Working of Locking...
Chittaranjan Pradhan
T1 T2 Concurrency-Control Manager
Lock-X(A)
Grant-X(A, T1 ) Need of Concurrency
Control
Read(A);
A:=A-100; Lock-Based Protocols
Basic Rules for Locking
Write(A); Working of Locking
Lock-S(A)
Locking Protocol
T3 T2 Concurrency-Control Manager
Lock-X(B) Need of Concurrency
Grant-X(B, T3 ) Control
Read(B); Lock-Based Protocols
B:=B-100; Basic Rules for Locking
Write(B); Working of Locking
Lock-S(A)
Locking Protocol
Grant-S(A, T2 )
Read(A);
Lock-S(B);
Lock-X(A)
Locking Protocol
Need of Concurrency
Control
• At this point, T1 may release the lock, but still T2 has to
Lock-Based Protocols
wait for T3 to finish. There may be a new transaction T4 Basic Rules for Locking
Working of Locking
that requests a shared-mode lock on the same data item,
Locking Protocol
and is granted the lock before T3 releases it
• In such a situation, T2 never gets the exclusive-mode lock
on the data item. Thus, T2 cannot progress at all and is
said to be starved. This problem is called as the starvation
problem
We can avoid starvation of transactions by granting locks in the
following manner; when a transaction Ti requests a lock on a
data item Q in a particular mode M, the concurrency-control
manager grants the lock provided that:
• There is no other transaction holding a lock on Q in a
mode that conflicts with M
• There is no other transaction that is waiting for a lock on Q
and that made its lock request before Ti
21.18