Unit - I DBMS
Unit - I DBMS
Systems
SCHOOL OF COMPUTER ENGINEERING AND TECHNOLOGY
Database Management Systems
Course Objectives:
1.Understand and successfully apply logical database design principles, including E-R diagrams and database
normalization.
2. Learn Database Programming languages and apply in DBMS applications.
3. Understand transaction processing and concurrency control in DBMS.
4. Learn database architectures, DBMS advancements and its usage in advance applications.
Course Outcomes: Upon completion of the course, the students will be able to:
1.Design ER-models to represent simple database application scenarios and Improve the database design by
normalization.
2. Design Database Relational Model and apply SQL , PLSQL concepts for database programming.
3. Describe Transaction Processing and Concurrency Control techniques for databases.
4. Identify appropriate database architecture for the real world database applications.
DATABASE MANAGEMENT 2
SYSTEMS
Introduction to Database Management Systems and Data
Modeling
Syllabus :
DBMS Vs File Systems, Database System Architecture, Data Abstraction, Data
Independence, Data Definition and Data Manipulation Languages, Database
System Internals-Components of a database system,
Data Models , E-R diagram: Components of E-R Model, Conventions, Keys, EER
diagram Components, E-R diagram into tables, Relational Model, Relational
Integrity, Referential Integrities, Enterprise Constraints, Schema Diagram,
Relational Algebra- Basic Operations, Normalization.
DATABASE MANAGEMENT 3
SYSTEMS
Database Management System Basics
DATABASE MANAGEMENT 4
SYSTEMS
Motivation for Database Management Systems
Traditional file Systems have following drawbacks to store data :
▪ Data Redundancy and Inconsistency
⮚ Multiple file formats, duplication of information in differentfiles
Difficulty in accessing data
⮚Need to write a new program to carry out each new task.
▪ Data Isolation
⮚ Multiple files andformats.
Question : What can be other drawbacks related to usage of file systems ?
DATABASE MANAGEMENT 5
SYSTEMS
Motivation for Database Management Systems
Answer : Traditional file Systems have following drawbacks to store data:
▪ Integrity Problems
⮚Integrity constraints (e.g., account balance > 0) become “buried” in
program code rather than being stated explicitly
⮚Difficult to add new constraints or change existing ones
▪ Atomicity of Updates
⮚Failures may leave database in an inconsistent state with partial updates
carried out.
DATABASE MANAGEMENT 6
SYSTEMS
Motivation for Database Management Systems
Traditional file Systems have following drawbacks to store data :
▪ Concurrent Access by Multiple users
⮚Concurrent access needed for performance.
⮚Uncontrolled concurrent accesses can lead to inconsistencies.
▪ Security Problems
⮚Hard to provide user access to some, but not all, data
Database Management Systems offers solutions to all the above
problems/limitations of traditional file systems.
DATABASE MANAGEMENT 7
SYSTEMS
Database System Architectures
DATABASE MANAGEMENT 22
SYSTEMS
Data Independence
Types of Data Independence :
▪ Physical Data Independence : the ability to modify the physical schema without
changing the logical schema
⮚ Applications depend on the logical schema
⮚In general, the interfaces between the various levels and components should be
well defined so that changes in some parts do not seriously influence others.
▪Logical Data Independence : the ability to change the conceptual scheme without
changing
⮚External views
⮚External API or programs
⮚Any change made will be absorbed by the mapping between external and
conceptual levels.
⮚When compared to Physical Data independence, it is challenging to achieve
logical data independence.
DATABASE MANAGEMENT 23
SYSTEMS
Database System Languages
DATABASE MANAGEMENT 25
SYSTEMS
Database System Structure/Architecture
Important Components of
Database System :
⮚Database Users
⮚Query Processing
⮚Storage Management
⮚Transaction Management
DATABASE MANAGEMENT 26
SYSTEMS
Database System Components : Database Users
⮚Naive Users
⮚Application Programmers
⮚Sophisticated Users
⮚Database Administrators
DATABASE MANAGEMENT 27
SYSTEMS
Database System Components : Query Processing
Query Processing
Steps :
1.Parsing and
Translation
2.Optimization
3.Evaluation
DATABASE MANAGEMENT 28
SYSTEMS
Database System Components :Storage
Management
DATABASE MANAGEMENT 29
SYSTEMS
Database System Components :Transaction
Management
DATABASE MANAGEMENT 30
SYSTEMS
Entity Relationship Model
▪ A database can be modeled as:
◦ a collection of entities,
◦ relationship among entities.
▪ An entity is an object that exists and is distinguishable
from other objects.
◦ Example: specific person, company, event, plant
▪ Entities have attributes
◦ Example: people have names and addresses
▪ An entity set is a set of entities of the same type that
share the same properties.
◦ Example: set of all persons, companies, trees,
holidays
DATABASE MANAGEMENT 31
SYSTEMS
Relationship Sets
DATABASE MANAGEMENT 33
SYSTEMS
Degree of a Relationship Set
DATABASE MANAGEMENT 34
SYSTEMS
Attributes
▪ Attribute types
⮚ Simple and composite attributes. ▪An entity is represented by a set of
⮚ Single-valued and multivalued attributes. attributes, that is descriptive properties
Example: multivalued attribute: possessed by all members of an entity set.
phone_numbers ◦ Example:
⮚ Derived attributes instructor = (ID, name, street, city,
Can be computed from other attributes salary )
Example: age, given date_of_birth course= (course_id, title, credits)
▪ Domain – the set of permitted values for
each attribute
DATABASE MANAGEMENT 35
SYSTEMS
Mapping Cardinality Constraints
DATABASE MANAGEMENT 37
SYSTEMS
Entity Relationship Diagram
DATABASE MANAGEMENT 38
SYSTEMS
Entity-Relationship Diagram
It is a graphical Representation of ER Model
Basic Notations :
DATABASE MANAGEMENT 39
SYSTEMS
Entity Relationship Diagram Continued
▪ Entity With Composite, ▪ Relationship Sets with Attributes
Multivalued, and Derived
Attributes
DATABASE MANAGEMENT 40
SYSTEMS
Entity Relationship Diagram Continued
Roles
⮚ Entity sets of a relationship need not be distinct.
⮚Each occurrence of an entity set plays a “role” in the relationship.
The labels “course_id” and “prereq_id” are called roles.
DATABASE MANAGEMENT 41
SYSTEMS
Entity Relationship Diagram Continued
Cardinality Constraints
⮚We express cardinality constraints by drawing either a directed line (→), signifying “one,” or
an undirected line (—), signifying “many,” between the relationship set and the entity set.
1. One-to-One Relationship
one-to-one relationship between an
instructor and a student
◦ an instructor is associated with at
most one student via advisor
◦ and a student is associated with at
most one instructor via advisor
DATABASE MANAGEMENT 42
SYSTEMS
Entity Relationship Diagram Continued
b. One-to-Many Relationship
A one-to-many relationship between an instructor and a student
⮚a an instructor is associated with several (including 0) students viaadvisor
⮚student is associated with at most one instructor via advisor
c. Many-to-One Relationship
In a many-to-one relationship between an instructor and a student,
⮚an instructor is associated with at most one student via advisor,
⮚and a student is associated with several (including 0) instructors via advisor
d. Many-to Many Relationship
⮚An instructor is associated with several (possibly 0) students via advisor
DATABASE MANAGEMENT 44
SYSTEMS
Entity Relationship Diagram : Weak Entity Sets
⮚An entity set that does not have a primary key is referred to as a
weak entity set.
⮚The existence of a weak entity set depends on the existence of a
identifying entity set
◦ It must relate to the identifying entity set via a total, one-to-
many relationship set from the identifying to the weak entity
set
◦ Identifying relationship depicted using a double diamond ▪ We underline the discriminator of a
weak entity set with a dashed line.
⮚The discriminator (or partial key) of a weak entity set is the set ▪ We put the identifying relationship
of attributes that distinguishes among all the entities of a weak of a weak entity in a double
entity set.
diamond.
The primary key of a weak entity set is formed by the primary key ▪ Primary key for section –
of the strong entity set on which the weak entity set is existence (course_id, sec_id, semester, year)
dependent, plus the weak entity set’s discriminator.
DATABASE MANAGEMENT 45
SYSTEMS
Example of Strong and Weak Entity
Strong Entity :
Professor(ID,Name,City,Salary)
Weak Entity :
Dependent(Name,DOB,Relation)
The Dependent Entity will share the ID
attribute of Professor.
Resultant Schema :
Dependent(ID,Name,DOB,Relation)
The primary key for Weak Entity Dependent
will be ID + Name as Name is the
discriminator attribute.
DATABASE MANAGEMENT 46
SYSTEMS
E-R Diagram Example
Question : Design an ER Diagram for Airline Reservation scenario given below :
The flight database stores details about an airline’s fleet, flights, and seat bookings.
Consider the following scenario:
• The airline has one or more airplanes.
• An airplane has a model number, a registration number, and the capacity to take one or more passengers.
• An airplane flight has a unique flight number, a departure airport, a destination airport, a departure date
and time, and an arrival date and time.
• Each flight is carried out by a single airplane.
• A passenger has given names(first name, last name),contact and a unique email address.
• Passengers can book seats on flights.
DATABASE MANAGEMENT 47
SYSTEMS
Flight Reservation ERD
Last
Name
Contact
Airline Passenger
_name Airline
Name
Email
Has Books
First
NAme
Model
_no
Flight_ Arrival_Dat
Capacity
No e_Time
From Departure
_Date_Ti
me
DATABASE MANAGEMENT 48
SYSTEMS
Extended ER Features :
⮚ Specialization
⮚ Generalization
⮚ Aggregation
DATABASE MANAGEMENT 49
SYSTEMS
Extended ER Features : Specialization
⮚Top-down design process; we designate subgroupings within an entity set that are distinctive from other
entities in the set.
⮚These subgroupings become lower-level entity sets that have attributes or participate in relationships
that do not apply to the higher-level entity set.
⮚Depicted by a triangle component labeled IS A (E.g., instructor “is a” person).
⮚Attribute inheritance – a lower-level entity set inherits all the attributes and relationship participation
of the higher-level entity set to which it is linked.
DATABASE MANAGEMENT 50
SYSTEMS
Specialization : Example
DATABASE MANAGEMENT 51
SYSTEMS
Extended ER Features : Generalization
⮚A bottom-up design process – combine a number of entity sets that share the same
features into a higher-level entity set.
⮚Specialization and generalization are simple inversions of each other; they are
represented in an E-R diagram in the same way.
⮚The terms specialization and generalization are used interchangeably.
DATABASE MANAGEMENT 52
SYSTEMS
Generalization : Example
DATABASE MANAGEMENT 53
SYSTEMS
Extended ER Features : Aggregation
DATABASE MANAGEMENT 54
SYSTEMS
Extended ER Features : Aggregation
⮚Eliminate this redundancy via aggregation
▪ Treat relationship as an abstract entity
▪ Allows relationships between relationships
▪ Abstraction of relationship into new entity
DATABASE MANAGEMENT 55
SYSTEMS
Reduction of ER Diagram to
Relation Schemas
DATABASE MANAGEMENT 56
SYSTEMS
Reduction to Relation Schemas
DATABASE MANAGEMENT 57
SYSTEMS
Reduction to Relation Schemas
Inst_d
Dept Instructor
ept
Example: Instead of creating a schema for relationship set inst_dept, add an attribute
dept_name to the schema arising from entity set instructor
DATABASE MANAGEMENT 59
SYSTEMS
Reduction to Relation Schema
Representing Composite and Multi-valued
Attributes
▪ Composite attributes are flattened out by creating a
separate attribute for each component attribute
◦ Example: given entity set instructor with composite
attribute name with component attributes first_name and
last_name the schema corresponding to the entity set has
two attributes name_first_name and name_last_name
◦ Prefix omitted if there is no ambiguity
▪ Ignoring multivalued attributes, extended instructor schema is :
ID First_nam Middle_initial Last_name Street_ Street_ Apt_num city state zip Date_of
e number name ber _birth
DATABASE MANAGEMENT 60
SYSTEMS
Reduction to Relation Schema
Representing Composite and Multi-valued Attributes
A multivalued attribute M of an entity E is represented by a
separate schema EM
◦ Schema EM has attributes corresponding to the primary key of
E and an attribute corresponding to multivalued attribute M
◦ Example: Multivalued attribute phone_number of instructor is
represented by a schema:
inst_phone= ( ID, phone_number)
◦ Each value of the multivalued attribute maps to a separate tuple
of the relation on schema EM
◦ For example, an instructor entity with primary key 22222 ID Phone_number
and phone numbers 456-7890 and 123-4567 maps to two
tuples: 22222 456-7890
(22222, 456-7890) and (22222, 123-4567) 22222 123-4567
DATABASE MANAGEMENT 61
SYSTEMS
Extended ER Features Reduction to Relation Schemas
DATABASE MANAGEMENT 62
SYSTEMS
Example for Reduction of ER Diagram to Relation schemas
University
1 Reduced
Schema-
Names
Contains Universit
y
N Facult
y
Faculty Scho
1 ol
Progra
Divided m
into Lecture
r
Cours
1 N 1 e
School offers Program Studen
1 t
Full-
time_
Employe
contains Lecturer
e Part-
time_Lecture
M N r
M N Lect_Cours
Lecturer teaches Course enrolls e
N (Associativ
IS
e Entity
A
due to
enrolls Student_Course
Contact M:M)
( Associative
Full-Time Part-time N Entity due to
Lecturer DATABA MANAGEMENT
Lecturer N 5
SE SYSTEMS Student M:M) 0
Relational Algebra
DATABASE MANAGEMENT 64
SYSTEMS
Relational Algebra
Example of selection:
▪ Notation: σ p(r)
Account(account_number, branch_name,balance)
p is called the selection predicate σ branch-name=“Perryridge”(account)
⮚Defined as:
A B C D A B C D
σp(r) = {t | t ∈r and p(t)} α 1 7 α 1 7
α α
⮚ Where p is a formula in propositional
calculus consisting of terms connected by : ∧ α β 5 7 β β 23 10
(and), ∨(or), ¬ (not)
Each term is one of: β β 12 3
<attribute> op <attribute> or <constant> σA=B ^ D > 5 (r)
β β 23 10
where op is one of: =, ≠, >, ≥. <. ≤
Relation r
DATABASE MANAGEMENT SYSTEMS 66
Relational Algebra: Project Operation
▪ Notation : rxs A B C D E
C D E
α 1 α 10 a
α 10 a
α 1 β 10 a
Assume that attributes of r(R) and s(S) are disjoint.
(That is, R ∩ S = ∅). β 10 a
A B r ⅹs α 1 β 20 b
If attributes of r(R) and s(S) are not disjoint, then 1
renaming must be used. α β 20 b
α 1 γ 10 b
β 2 γ 10 B β 2 α 10 a
β 2 β 10 a
Relation r
Relation s β 2 β 20 b
β 2 γ 10 b
▪ Notation : r ⋈s
▪ We can perform a Natural Join only if there is
at least one common attribute that exists
between two relations
▪ The common attributes must have the same
name and domain. A B A C r ⋈s A B C
▪ Natural join acts on those matching attributes
α 1 α 10 α 1 10
where the values of attributes in both the
relations are same. β 30 β 2 30
β 2
▪ It avoids duplication of columns while
providing the result as compared to other
joins/cartesian-product. Relation r Relation s
DATABASE MANAGEMENT 72
SYSTEMS
References
Text Books:
• Abraham Silberschatz, Henry F. Korth and S. Sudarshan, Database System Concepts 6th
Ed, McGraw Hill, 2010.
• Elmasi, R. and Navathe, S.B., “Fundamentals of Database Systems”, 4th
• Ed., Pearson Education.
Reference Books :
• Ramakrishnan, R. and Gherke, J., “Database Management Systems”, 3rd Ed., McGraw-
Hill.
• Connally T, Begg C.,”Database Systems”,Pearson Education
DATABASE MANAGEMENT 73
SYSTEMS
End
DATABASE MANAGEMENT 74
SYSTEMS