0% found this document useful (0 votes)
58 views

Dbms Complete Notes

BCA 3rd Sen dbms notes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
58 views

Dbms Complete Notes

BCA 3rd Sen dbms notes
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 66

Database management system-21BCA3C7DML

UNIT 1: DATABASE ARCHIETECTURE


Data: it is collection of raw facts which can be processed and made into meaningful
information

Database : it is collection of related data setup for easy access management and updating.

DBMS: A database management system (DBMS) is a software for creating and managing
databases
Example:
Oracle RDBMS
IBM DB2
Microsoft SQL Server
MySQL

Advantages of DBMS:
Improved Data Sharing: DBMS enables data sharing among multiple users and applications.
Multiple users can access the same data simultaneously, without interfering with each other's
work.
Data Integration: DBMS allows the integration of data from multiple sources. This means that
data can be collected from various systems and combined into a single database, which makes it
easier to access and analyze.
Data Security: DBMS provides various security features such as access control, authentication,
and encryption to safeguard data from unauthorized access and prevent data loss or corruption.
Data Consistency: DBMS enforces consistency in data by ensuring that data is accurate,
complete, and up-to-date. This helps to avoid data inconsistencies and errors
Data Integrity: DBMS ensures that data is stored and retrieved without any loss or corruption. It
provides mechanisms such as transaction management and recovery
Eliminate data redundancy(duplication): separate parts of database should correlate
To reduce data redundancy and provides efficient data update duplication of data is eliminated.

Disadvantages of DBMS:
High Cost: Implementing a DBMS can be expensive due to the cost of licensing, hardware, and
maintenance.
Complexity: DBMS is a complex software that requires a significant amount of technical
expertise to install, configure, and maintain.
System Overhead: DBMS requires system resources such as memory, CPU, and disk space,
which can lead to system overhead and reduced system performance.
Data Dependency: DBMS stores data in a particular format, which can create data dependency
issues. If the format changes, it can affect the application that uses the data, leading to additional
maintenance and development costs.
Single Point of Failure: DBMS represents a single point of failure for an organization's data. If
the DBMS fails, it can lead to significant data loss and downtime,

NIMS BCA DEPT DBMS NOTES Page 1


Database management system -21BCA3C7DML

Characteristics of database approach :


Some of the most important characteristics of the database approach to the file processing
approach are the following as follows
1. Self-Describing Nature of a Database System : One of the most fundamental
characteristics of the database approach is that the database system contains not only the
database itself but also an entire definition or description of the database structure and
constraints also known as metadata of the database.
2. isolation between Programs and Data, and Data Abstraction :
In a traditional file processing system, the structure of database knowledge files is
embedded within the application programs, so any changes to the structure of a file may
require changing all programs that access that file.
3. Support for Multiple Views of the Data :
A database sometimes has many users, each of whom may require a special perspective or
view of the database.
4. Sharing of knowledge and Multi-user Transaction Processing :
A multi-user DBMS, as its name implies, must allow multiple users to access the
database at an equivalent time or concurrently.
5. The atomicity property ensures that either all the database operations during a transaction
are executed or none are, these all ACID(atomicity, Consistency, Isolation, and Durability)
properties we know.

Applications of database system


1. Railway Reservation System –
In the rail route reservation framework, the information base is needed to store the
record or information of ticket appointments, status about train’s appearance, and flight.
2. Library Management System –
There are lots of books in the library so; it is difficult to store the record of the relative
multitude of books in a register or duplicate. (DBMS) is utilized to keep up all the data
identified with the name of the book, issue date, accessibility of the book, and its
writer.
3. Banking –
Database the executive’s framework is utilized to store the exchange data of the client
in the information base.
4. Education Sector –
Presently, assessments are led online by numerous schools and colleges. They deal with
all assessment information through the data set administration framework (DBMS).
5. Credit card exchanges –
The database Management framework is utilized for buying on charge cards and age of
month to month proclamations.
6. Social Media Sites
7. Broadcast communications
8. Account
9. Online Shopping

NIMS BCA DEPT DBMS NOTES Page 2


Database management system-21BCA3C7DML

10. Human Resource Management –


Big firms or organizations have numerous specialists or representatives working under
them. They store data about worker’s compensation, assessment, and work with the
assistance of an information base administration framework (DBMS).

People associated with database system:


There are two categories of people behind DBMS. They are:
1. Actors on the scene
2. Workers behind the scene
1) Actors on the scene:
The persons involved in the design, use and maintenance of large databases are:
Database Administrator (DBA)
➢ Database Designer
➢ End User
➢ Software Engineer (System Analyst and Application Programmer)
2) Workers behind the scene:
The persons who work to maintain the database environment but are not actively involved in the
database itself are:
➢ DBMS system designers and implementers
➢ Tool developers
➢ Operators and maintenance personnel.

Database Administrators:
➢ DBA is a single person or a group of persons responsible for implementing the database
system within an organisation
➢ DBA is a centralized control of the database management system (both data & application
programs).
➢ The main functionality of DBA is to provide convenient and efficient atmosphere for database
users and access the data.
➢ The entire control of DBMS is in the hands of DBA

The DBA has following roles and responsibilities regarding database management.
1. Providing schema definition and modification: The overall design of the D/B is known as
schema. DBA is responsible to provide schema (logical and physical) of the/B is known as
schema.
2. Granting user authorization: DBA can grant authorization of data access to different users so
that database will not be accessible by unauthorized users.
3. Backup and recovery: DBA is responsible for taking the database backup periodically in order
to be able to recover data from any failures (like virus attack).
4. New Software installation: Installing how DBMS s/w, application S/W &S/W &another
related s/w. 5. Monitoring performance: BA monitor the CPU and memory usage of computer,
the performance of the DB.

NIMS BCA DEPT DBMS NOTES Page 3


Database management system -21BCA3C7DML

Database Designers: Database Designers are responsible for identifying the data to be stored
in the database and for choosing appropriate structures to represent and store this data.
Database designers typically interact with each potential group and user and develop a view of
the database that meets the data and processing requirements of these groups.

End Users: End users are the people whose jobs require access to the database for querying,
updating, and generating reports; the database primarily exists for their use. There are several
categories of end users:
Casual end user: Occasionally access the database, but they may need different information
each time. They are typically middle-or high-level managers or other occasional browsers.
Naive or Parametric end user: Their main job function revolves around constantly querying
and updating the database, using standard types of queries and updates that have been carefully
programmed and tested. Bank tellers, Reservation Clerks for airlines, hotels, etc are the
example of Naive end users.
Sophisticated end users: Sophisticated end users include engineers, scientists, business
analysts, and others who thoroughly familiarize themselves with the facilities of the DBMS so
as to implement their applications to meet their complex requirements.
Stand-alone users: They maintain the personal databases by using ready-made program
packages that provide an easy-to-use menu or graphics-based interfaces.

Software Engineers: System analysts determines the requirements of end users, especially
naive and parametric end users, and develop specifications for canned transactions that meet
these requirements.Application programmers implement these specifications as programs; then
they test, debug, document, and maintain these canned transactions. Such analysts and
programmers are called Software Engineers.

Data Models
➢ A data model is a collection of concepts that can be used to describe the structure of a
database
. ➢ By structure of a database, the data types, relationships and constraints that should hold for
the data.
➢ Most data models also include a set of basic operations for specifying retrievals and updates
on the database.
The most often used data models are:
1. Hierarchical Model
2. Network Model
3. Relational Model
4. Object-Oriented Model

1. Hierarchical Model:
1. A Hierarchical Database Model is a data model in which the data is organized into a tree
structure.
2. The data is stored as records which are connected to one another through links.

NIMS BCA DEPT DBMS NOTES Page 4


Database management system-21BCA3C7DML

3. A record is a collection of fields, with each field containing only one value.
4. At the top of hierarchy there is only one entity which is called Root

. Advantages:
1. The model allows easy addition and deletion of new information.
2. Data at the top of the Hierarchy is very fast to access.
3. The model relates, very well to natural hierarchies such as assembly plants and employee
organization in corporations.
Disadvantages:
1. Complex implementation.
2. Predefined tree structure reduces flexibility.
3. The database can be very slow when searching for information on the lower entities.

2. Network Model:
1. The Network Model is a database model conceived as a flexible way of representing
objects and their relationships.
2. Its distinguishing feature is that the schema, viewed as a graph in which object types are
nodes and relationship types are arcs.
3. The Objects or entities can be accessed through several paths.

NIMS BCA DEPT DBMS NOTES Page 5


Database management system -21BCA3C7DML

Advantages:
1. The network model is also conceptually simple and easy to design.
2. The network model can handle the one to many and many to many relationships which is
real help in modeling the real-life situations.
3. The data access is easier and flexible than the hierarchical model.
4. The network model does not allow a member to exist without an owner.
5. The network model is better than the hierarchical model in isolating the programs from
the complex physical storage details.
Disadvantages:
1. All the records are maintained using pointers and hence the whole database
2. structure becomes very complex. The insertion, deletion and updating operations of any
record require large number of pointers adjustments.
3. Structural changes to the database are very difficult.

3. Relational Model:
1. The Relational Model for database management is an approach to managing data using a
structure and language described in 1969 by Edgar F. Codd.
2. In the relational model of a database, all data is represented in terms of tuples, grouped
into relations.
3. A database organized in terms of the relational model is a relational database.

NIMS BCA DEPT DBMS NOTES Page 6


Database management system-21BCA3C7DML

Advantages:
1. Tables consisting of rows and columns are much easier to understand.
2. Different tables from which information has to be linked and extracted can be easily
manipulated by operators such as project and join to give information in the form in
which it is desired
3. The usage of relational algebra and relational calculus in the manipulation of the
4. relations between the tables ensures that there is no ambiguity.
5. Security control and authorization can also be implemented more easily by moving
sensitive attributes in a given table into a separate relation with its own authorization
controls.
6. Data independence is achieved more easily with normalization structure used in a
relational database than in the more complicated tree or network structure.
Disadvantages:
1. Performance is a major constraint and therefore disadvantage in the use of relational
database system is machine performance.
2. Physical storage consumption.
3. Slow extraction of meaning from data

4. Object-Oriented Model
1. Object-oriented models define a database as a collection of objects with features and
methods.
2. An object database (also Object-Oriented Database Management System, (OODBMS) is
a Database Management System in which information is represented in the form of
objects as used in object-oriented programming.

NIMS BCA DEPT DBMS NOTES Page 7


Database management system -21BCA3C7DML

Advantages:
1. Applicability to advanced database applications.
2. Improved performance.
3. Support for schema evolution.
4. Enriched modeling capabilities.
5. Extensibility.
6. Capable of handling a large variety of data types.
7. Removal of impedance mismatch.
8. More expressive query language
. Disadvantages:
1. Lack of universal data.
2. Query optimization compromises encapsulations Lack of support for security.

Schema
The Skeleton of the database is created by the attributes and this skeleton is named Schema.
Schema mentions the logical constraints like table, primary key, etc.
The schema does not represent the data type of the attributes.

Database Schema
A database schema is a logical representation of data that shows how the data in a database
should be stored logically. It shows how the data is organized and the relationship between the
tables.

NIMS BCA DEPT DBMS NOTES Page 8


Database management system -21BCA3C7DML

1. Database schema contains table, field, views and relation between different keys
like primary key, foreign key.
2. Data are stored in the form of files which is unstructured in nature which makes
accessing the data difficult. Thus to resolve the issue the data are organized in
structured way with the help of database schema.
3. Database schema provides the organization of data and the relationship between the
stored data.
4. Database schema defines a set of guidelines that control the database along with that it
provides information about the way of accessing and modifying the data

There are 3 types of database schema


Physical Database Schema
A Physical schema defines, how the data or information is stored physically in the storage
systems in the form of files & indices.
Logical Database Schema
A logical database schema defines all the logical constraints that need to be applied to the
stored data, and also describes tables, views, entity relationships, and integrity constraints.
View Database Schema
It is a view level design which is able to define the interaction between end-user and database.

Database Architecture
A Database Architecture is a representation of DBMS design. It helps to design, develop,
implement, and maintain the database management system. A DBMS architecture allows

NIMS BCA DEPT DBMS NOTES Page 9


Database management system-21BCA3C7DML

dividing the database system into individual components that can be independently modified,
changed, replaced, and altered. It also helps to understand the components of a database.

There are mainly three types of DBMS architecture:


1. One Tier Architecture (Single Tier Architecture)
2. Two Tier Architecture
3. Three Tier Architecture
1 Tier Architecture in DBMS is the simplest architecture of Database in which the client,
server, and Database all reside on the same machine. A simple one tier architecture example
would be anytime you install a Database in your system and access it to practice SQL queries.
But such architecture is rarely used in production.

2-Tier Architecture
A 2 Tier Architecture in DBMS is a Database architecture where the presentation layer runs on
a client (PC, Mobile, Tablet, etc.), and data is stored on a server called the second tier. Two tier
architecture provides added security to the DBMS as it is not exposed to the end-user directly. It
also provides direct and faster communication.

In the above 2 Tier client-server architecture of database management system, we can see that
one server is connected with clients 1, 2, and 3.
Two Tier Architecture Example:
A Contact Management System created using MS- Access.

NIMS BCA DEPT DBMS NOTES Page 10


Database management system-21BCA3C7DML

3-Tier Architecture
A 3 Tier Architecture in DBMS is the most popular client server architecture in DBMS in
which the development and maintenance of functional processes, logic, data access, data storage,
and user interface is done independently as separate modules. Three Tier architecture contains a
presentation layer, an application layer, and a database server.

3-Tier database Architecture design is an extension of the 2-tier client-server architecture. A 3-


tier architecture has the following layers:
Presentation layer (your PC, Tablet, Mobile, etc.)
Application layer (server)
Database Server

The Application layer resides between the user and the DBMS, which is responsible for
communicating the user’s request to the DBMS system and send the response from the DBMS to
the user. The application layer(business logic layer) also processes functional logic, constraint,
and rules before passing data to the user or down to the DBMS.

The goal of Three Tier client-server architecture is:


To separate the user applications and physical database
To support DBMS characteristics
Program-data independence
Supporting multiple views of the data
Example:
Any large website on the internet, including guru99.com.

Data Independence
Data independence can be explained using the three-schema architecture.
Data independence refers characteristic of being able to modify the schema at one level of the
database system without altering the schema at the next higher level.
. External level:
1. It is also called View level.
2. The user does not need to know the database schema details such as data structure, table
definition etc. User is only concerned about data which is what returned back to the wave
level after it has been fetched from database.

NIMS BCA DEPT DBMS NOTES Page 11


Database management system-21BCA3C7DML

3. The reason this level is called “view” is because several users can weave their desired
data from this level which is internally fetched from database with the help of conceptual
and internal level mapping.
4. External level is the “Top level”

Logical Data Independence


1. Logical data independence refers characteristic of being able to change the conceptual
schema without having to change the external schema.
2. Logical data independence is used to separate the external level from the conceptual
view.
3. If we do any changes in the conceptual view of the data, then the user view of the data
would not be affected.
4. Logical data independence occurs at the user interface level.

Physical Data Independence


1. Physical data independence can be defined as the capacity to change the internal schema
without having to change the conceptual schema.
2. If we do any changes in the storage size of the database system server, then the
Conceptual structure of the database will not be affected.
3. Physical data independence is used to separate conceptual levels from the internal levels.
4. Physical data independence occurs at the logical interface level.

NIMS BCA DEPT DBMS NOTES Page 12


Database management system-21BCA3C7DML

Database Languages

1. Data Definition Language (DDL)


1. DDL stands for Data Definition Language. It is used to define database structure or
pattern.
2. It is used to create schema, tables, indexes, constraints, etc. in the database.
3. Using the DDL statements, you can create the skeleton of the database.
4. Data definition language is used to store the information of metadata like the number of
tables and schemas, their names, indexes, columns in each table, constraints, etc.

Here are some tasks that come under DDL:


1. Create: It is used to create objects in the database.
2. Alter: It is used to alter the structure of the database.
3. Drop: It is used to delete objects from the database.
4. Truncate: It is used to remove all records from a table.
5. Rename: It is used to rename an object.
6. Comment: It is used to comment on the data dictionary.
These commands are used to update the database schema that's why they come under Data
definition language.

2. Data Manipulation Language (DML)


DML stands for Data Manipulation Language. It is used for accessing and manipulating data in
a database. It handles user requests.

1. Select: It is used to retrieve data from a database.


2. Insert: It is used to insert data into a table.
3. Update: It is used to update existing data within a table.
4. Delete: It is used to delete all records from a table.
5. Merge: It performs UPSERT operation, i.e., insert or update operations.
6. Call: It is used to call a structured query language or a Java subprogram.
7. Explain Plan: It has the parameter of explaining data.
8. Lock Table: It controls concurrency.

NIMS BCA DEPT DBMS NOTES Page 13


Database management system-21BCA3C7DML

3. Data Control Language (DCL)


DCL stands for Data Control Language. It is used to retrieve the stored or saved data.
The DCL execution is transactional. It also has rollback parameters.
(But in Oracle database, the execution of data control language does not have the feature of
rolling back.)

Here are some tasks that come under DCL:


1. Grant: It is used to give user access privileges to a database.
2. Revoke: It is used to take back permissions from the user.

4. Transaction Control Language (TCL)


TCL is used to run the changes made by the DML statement. TCL can be grouped into a logical
transaction.
Here are some tasks that come under TCL:
1. Commit: It is used to save the transaction on the database.
2. Rollback: It is used to restore the database to original since the last Commit.

Interfaces
A database management system (DBMS) interface is a user interface that allows for the ability
to input queries to a database without using the query language itself. User-friendly interfaces
provided by DBMS may include the following:
1. Menu-Based Interfaces
2. Forms-Based Interfaces
3. Graphical User Interfaces
4. Interfaces for the Database Administrator (DBA)
Menu-Based Interfaces
These interfaces present the user with lists of options (called menus) that lead the user through
the formation of a request. The basic advantage of using menus is that they remove the tension
of remembering specific commands and syntax of any query language. The query is basically
composed step by step by collecting or picking options from a menu that is shown by the
system. Pull-down menus are a very popular technique in Web-based interfaces.
Forms-Based Interfaces
A forms-based interface displays a form to each user. Users can fill out all of the form entries
to insert new data, or they can fill out only certain entries, in which case the DBMS will
redeem the same type of data for other remaining entries.
Example: SQL Forms is a form-based language that specifies queries using a form designed in
conjunction with the relational database schema.
Graphical User Interface
A GUI typically displays a schema to the user in diagrammatic form. The user then can specify
a query by manipulating the diagram. In many cases, GUI utilise both menus and forms. Most
GUI use a pointing device such as a mouse, to pick a certain part of the displayed schema
diagram.
Interfaces for Database Administrators (DBA)

NIMS BCA DEPT DBMS NOTES Page 14


Database management system-21BCA3C7DML

Most database system contains privileged commands that can be used only by the DBA’s staff.
These include commands for creating accounts, setting system parameters, granting account
authorization, changing a schema, and reorganizing the storage structures of databases

Classification of DBMS

1. Classification Based on Data Model


The most popular data model in use today is the relational data model. Well-known
DBMSs like Oracle, MS SQL Server, DB2 and MySQL support this model. Other
traditional models, such as hierarchical data models and network data models, are still
used in industry mainly on mainframe platforms. However, they are not commonly used
due to their complexity. These are all referred to as traditional models because they
preceded the relational model.
In recent years, the newer object-oriented data models were introduced. This model is a
database management system in which information is represented in the form of objects
as used in object-oriented programming.
2. Classification Based on User Numbers
A DBMS can be classification based on the number of users it supports. It can be
a single-user database system, which supports one user at a time, or a multiuser database
system, which supports multiple users concurrently.
3. Classification Based on Database Distribution
There are four main distribution systems for database systems and these, in turn, can be used to
classify the DBMS.
Centralized systems
With a centralized database system, the DBMS and database are stored at a single site that is
used by several other systems too.
Distributed database system
In a distributed database system, the actual database and the DBMS software are distributed
from various sites that are connected by a computer network
Homogeneous distributed database systems
Homogeneous distributed database systems use the same DBMS software from multiple sites.
Data exchange between these various sites can be handled easily.
Heterogeneous distributed database systems
In a heterogeneous distributed database system, different sites might use different DBMS
software, but there is additional common software to support data exchange between these sites.

NIMS BCA DEPT DBMS NOTES Page 15


Database management system-21BCA3C7DML

UNIT 2: E-R MODEL


ER Model
An Entity-Relationship Model represents the structure of the database with the help of a diagram.
ER Modelling is a systematic process to design a database as it would require you to analyze all
data requirements before implementing your database.

History of ER models
Peter Chen proposed ER Diagrams in 1971 to create a uniform convention that can be used as a
conceptual modeling tool. Many models were presented and discussed, but none were suitable. The
data structure diagrams offered by Charles Bachman also inspired his model.

Why Use ER Diagrams in DBMS?

 ER Diagram helps you conceptualize the database and lets you know which fields need to be
embedded for a particular entity
 ER Diagram gives a better understanding of the information to be stored in a database
 It reduces complexity and allows database designers to build databases quickly
 It helps to describe elements using Entity-Relationship models
 It allows users to get a preview of the logical structure of the database

Symbols Used in ER Model


ER Model is used to model the logical view of the system from a data perspective which
consists of these symbols:
 Rectangles: Rectangles represent Entities in the ER Model.
 Ellipses: Ellipses represent Attributes in the ER Model.
 Diamond: Diamonds represent Relationships among Entities. 
 Lines: Lines represent attributes to entities and entity sets with other relationship types. 
 Double Ellipse: Double Ellipses represent Multi-Valued Attributes.
 Double Rectangle: Double Rectangle represents a Weak Entity.

NIMS BCA DEPT DBMS NOTES Page 1


Database management system-21BCA3C7DML

Components of ER Diagram
ER Model consists of Entities, Attributes, and Relationships among Entities in a Database
System.

Entity
It is a “thing” or “object” in the real world. Which consists of either place, person,
animal, and so on.

Entity Set: An Entity is an object of Entity Type and a set of all entities is called an entity
set. For Example, E1 is an entity having Entity Type Student and the set of all students is
called Entity Set. In ER diagram, Entity Type is represented as:

NIMS BCA DEPT DBMS NOTES Page 2


Database management system-21BCA3C7DML

1. Strong Entity
A Strong Entity is a type of entity that has a key Attribute. Strong Entity does not depend on
other Entity in the Schema. It has a primary key, that helps in identifying it uniquely, and it is
represented by a rectangle. These are called Strong Entity Types.

2. Weak Entity
An Entity type has a key attribute that uniquely identifies each entity in the entity set. But
some entity type exists for which key attributes can’t be defined. These are called Weak Entity
types.

For Example, A company may store the information of dependents (Parents, Children,
Spouse) of an Employee. But the dependents don’t have existed without the employee. So
Dependent will be a Weak Entity Type and Employee will be Identifying Entity type for
Dependent, which means it is Strong Entity Type.
A weak entity type is represented by a Double Rectangle. The participation of weak entity
types is always total. The relationship between the weak entity type and its identifying strong
entity type is called identifying relationship and it is represented by a double diamond.

Weak Entity Types


1. Entity types that do not have key attributes of their own are called weak entity types.
2. They are sometimes known as child entity type or the subordinate entity type.
3. These entities are identified by being related to specific entities from another entity
typein combination with one of their attribute values. The other entity type is called the
identifying or owner entity type or parent entity type or dominant entity type. The
relationship type that relates a weak entity type always has a total participation
constraint with respect to its entity.
4. Entity types that have key attribute are called Strong entity types.
5. A weak entity type normally has a partial key, which is the set of attributes that can
uniquely identify weak entities that are related to the same owner entity. This partial
keyis sometimes called the discriminator.

NIMS BCA DEPT DBMS NOTES Page 3


Database management system-21BCA3C7DML

Attributes

Attributes are the properties that define the entity type. For example, Roll_No, Name, DOB,
Age, Address, and Mobile_No are the attributes that define entity type Student. In ER diagram,
the attribute is represented by an oval.

. Key Attribute
The attribute which uniquely identifies each entity in the entity set is called the key attribute.
For example, Roll_No will be unique for each student. In ER diagram, the key attribute is
represented by an oval with underlying lines.

2. Composite Attribute
An attribute composed of many other attributes is called a composite attribute. For example,
the Address attribute of the student Entity type consists of Street, City, State, and Country. In
ER diagram, the composite attribute is represented by an oval comprising of ovals.

3. Multivalued Attribute
An attribute consisting of more than one value for a given entity. For example, Phone_No (can
be more than one for a given student). In ER diagram, a multivalued attribute is represented by
a double oval.

NIMS BCA DEPT DBMS NOTES Page 4


Database management system-21BCA3C7DML

4. Derived Attribute
An attribute that can be derived from other attributes of the entity type is known as a derived
attribute. e.g.; Age (can be derived from DOB). In ER diagram, the derived attribute is
represented by a dashed oval.

The Complete Entity Type Student with its Attributes can be represented as:

Domains Of Attributes

A set of values that may be assigned to the attributes of each individual entity, in
an entity set is called the Value set or Domain.

Example 1: For employee entity, if age limit is 20 to 58, then the values set (domain) of
attribute age consists of integers from 20 to 58.Age: Domain is [20 – 58]
Example 2: Similarly, the value set for name attribute could be a set of alphabets and
some special characters.
Name: Domain is [a-z], [A-Z], blank space
Example 3: For salary attribute, the value set may be again a range from minimum of
5000 to maximum of 50000.

NIMS BCA DEPT DBMS NOTES Page 5


Database management system-21BCA3C7DML

Relationship Type and Relationship Set


A Relationship Type represents the association between entity types. For example, ‘Enrolled
in’ is a relationship type that exists between entity type Student and Course. In ER diagram,
the relationship type is represented by a diamond and connecting the entities with lines.

Degree of relationship
The number of different entity sets participating in a relationship set is called the degree of a
relationship set.

1. Unary Relationship: When there is only ONE entity set participating in a relation, the
relationship is called a unary relationship. For example, one person is married to only one
person.

Binary Relationship:
Binary relationship is a relationship between the instance of two entities type.
The Degree of relationship is Two.

Ternary Relationship:
Ternary Relationship is a relationship between the instance of three entities types.
The Degree of relationship is three.

Recursive relationship
A relationship between two entities of a similar entity type is called a recursive relationship.
Here the same entity type participates more than once in a relationship type with a different
role for each instance. In other words, a relationship has always been between occurrences in

NIMS BCA DEPT DBMS NOTES Page 6


Database management system-21BCA3C7DML

two different entities. However, the same entity can participate in the relationship. This is
termed a recursive relationship.

Attributes of Relationship Types Just like entities, relationship types can also have
attributes. For example, in the
works-for relationship, we can add an attribute “hours”, which describes the relationship
as works-for so many hours.

Structural Constraints
To understand Structural Constraints, we must take a look at Cardinality Ratios and
Participation Constraints. Cardinality Ratios of relationships : The entities are denoted by
rectangle and relationships by diamond.

There are numbers (represented by M and N) written above the lines which connect
relationships and entities. These are called cardinality ratios. These represent the maximum
number of entities that can be associated with each other through relationship, R

. Structural Constraints : Structural Constraints are also called Structural properties of a


database management system (DBMS). Cardinality Ratios and Participation Constraints taken
together are called Structural Constraints.

NIMS BCA DEPT DBMS NOTES Page 7


Database management system-21BCA3C7DML

Cardinality : There can be 4 types of cardinality –

1. One-to-one (1:1) – When one entity in each entity set takes part at most once in the
relationship, the cardinality is one-to-one.

2. One-to-many (1: N) – If entities in the first entity set take part in the relationship set at
most once and entities in the second entity set take part many times (at least twice), the
cardinality is said to be one-to-many.

NIMS BCA DEPT DBMS NOTES Page 8


Database management system-21BCA3C7DML

3. Many-to-one (N:1) – If entities in the first entity set take part in the relationship set many
times (at least twice), while entities in the second entity set take part at most once, the
cardinality is said to be many-to-one.

4. Many-to-many (N: N) – The cardinality is said to be many to many if entities in both the
entity sets take part many times (at least twice) in the relationship set.
Participation Constraints : Participation Constraints tell us that the participation in a
relationship can either be total or partial.

Participation Constraint
Participation Constraint is applied to the entity participating in the relationship set.

1. Total Participation – Each entity in the entity set must participate in the relationship.
If each student must enroll in a course, the participation of students will be total. Total
participation is shown by a double line in the ER diagram.

2. Partial Participation – The entity in the entity set may or may NOT participate in the
relationship. If some courses are not enrolled by any of the students, the participation in the
course will be partial.

NIMS BCA DEPT DBMS NOTES Page 9


Database management system-21BCA3C7DML

ER diagram
ER diagram of student

ER diagram of student management system

NIMS BCA DEPT DBMS NOTES Page 10


Database management system-21BCA3C7DML

NIMS BCA DEPT DBMS NOTES Page 11


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

UNIT 3 Relational data model


Relational Model in DBMS

E.F. Codd proposed the relational Model to model data in the form of relations or tables. After
designing the conceptual model of the Database using ER diagram, we need to convert the
conceptual model into a relational model which can be implemented using
any RDBMS language like Oracle SQL, MySQL, etc

The relational model represents how data is stored in Relational Databases. A relational
database consists of a collection of tables, each of which is assigned a unique name. Consider a
relation STUDENT with attributes ROLL_NO, NAME, ADDRESS, PHONE, and AGE shown
in the table.

Table Student
ROLL_NO NAME ADDRESS PHONE AGE

1 RAM DELHI 9455123451 18

2 RAMESH GURGAON 9652431543 18

3 SUJIT ROHTAK 9156253131 20

4 SURESH DELHI 18

Important Terminologies

1. Attribute: Attributes are the properties that define an entity. e.g.; ROLL_NO, NAME,
ADDRESS
2. Relation Schema: A relation schema defines the structure of the relation and represents the
name of the relation with its attributes. e.g.; STUDENT (ROLL_NO, NAME, ddepartment)
is the relation schema for STUDENT. If a schema has more than 1 relation, it is called
Relational Schema.
3. Tuple: Each row in the relation is known as a tuple. Relation Instance: The set of tuples
of a relation at a particular instance of time is called a relation instance. Table 1 shows the
relation instance of STUDENT at a particular time. It can change whenever there is an
insertion, deletion, or update in the database.
4. Degree: The number of attributes in the relation is known as the degree of the relation.
The STUDENT relation defined above has degree 5.
5. Cardinality: The number of tuples in a relation is known as cardinality.
6. Column: The column represents the set of values for a particular attribute. The
column ROLL_NO is extracted from the relation STUDENT.

NIMS BCA DEPT DBMS NOTES Page 1


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Characteristics of Relational Database Model

As we know we have several relations in a database. Now, each relation must be uniquely
identified. If it is not so, then it would create a lot of confusion. Here, we will discuss some
characteristics that when followed will automatically make a relation distinct in a database.

1. Each relation in a database must have a distinct or unique name which would separate it
from the other relations in a database.
2. A relation must not have two attributes with the same name. Each attribute must have a
distinct name.
3. Duplicate tuples must not be present in a relation.

4. Each tuple must have exactly one data value for an attribute. For example, below in the first
table, you can see that for Roll_No. 265 we have enrolled two students Jhoson and Charles, this
would not work. We must have only one student for one Roll_No.

NIMS BCA DEPT DBMS NOTES Page 2


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

5. Tuples in a relation do not have to follow a significant order as the relation is not order-
sensitive.
6. Similarly, the attributes of a relation also do not have to follow certain ordering, it’s up to the
developer to decide the ordering of attributes.

Relational model constraints

Domain Constraints

In a database table, domain constraints are guidelines that specify the acceptable values for a
certain property or field. These restrictions guarantee data consistency and aid in preventing the
entry of inaccurate or inconsistent data into the database. The following are some instances of
domain restrictions in a Relational Database Model −

1. Data type constraints − These limitations define the kinds of data that can be kept in a
column. A column created as VARCHAR can take string values, but a column specified as
INTEGER can only accept integer values.
2. Length Constraints − These limitations define the largest amount of data that may be put in
a column. For instance, a column with the definition VARCHAR(10) may only take strings
that are up to 10 characters long.
3. Range constraints − The allowed range of values for a column is specified by range
restrictions. A column designated as DECIMAL(5,2), for example, may only take decimal
values up to 5 digits long, including 2 decimal places.
4. Nullability constraints − Constraints on a column's capacity to accept NULL values are
known as nullability constraints. For instance, a column that has the NOT NULL definition
cannot take NULL values.
5. Unique constraints − Constraints that require the presence of unique values in a column or
group of columns are known as unique constraints. For instance, duplicate values are not
allowed in a column with the UNIQUE definition.
6. Check constraints − Constraints for checking data: These constraints outline a requirement
that must hold for any data placed into the column. For instance, a column with the definition
CHECK (age > 0) can only accept ages that are greater than zero.

NIMS BCA DEPT DBMS NOTES Page 3


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

7. Default constraints − Constraints by default: Default constraints automatically assign a


value to a column in case no value is provided. For example, a column with a DEFAULT
value of 0 will have 0 as its value if no other value is specified.

Key Constraints

Key constraints are regulations that a Relational Database Model uses to ensure data accuracy
and consistency in a database. They define how the values in a table's one or more columns are
related to the values in other tables, making sure that the data remains correct.
In Relational Database Model, there are several key constraint kinds, including −

1. Primary Key Constraint − A primary key constraint is an individual identifier for each
record in a database. It guarantees that each database entry contains a single, distinct value—
or a pair of values—that cannot be null—as its method of identification.
2. Foreign Key Constraint − Reference to the primary key in another table is a foreign key
constraint. It ensures that the values of a column or set of columns in one table correspond to
the primary key column(s) in another table.
3. Unique Constraint − In a database, a unique constraint ensures that no two values inside a
column or collection of columns are the same.

Integrity constraint

Integrity constraints in DBMS can be defined as a collection of rules used to ensure the
quality of information. This assures that data insertion, modification, and other operations do
not affect data integration. There are mainly four types of integrity constraints, namely,
domain constraint, referential integrity constraint, entity integrity constraint, and key
constraint.

Types of Integrity Constraints in DBMS


In DBMS, four types of integrity constraints play a crucial role in maintaining data integrity
and enforcing business rules.
1. Domain Constraint
A domain constraint defines the valid range of values that a column can hold. It specifies a
column’s data type, format, and allowable values. By enforcing domain constraints, data
consistency and validity can be ensured, preventing inappropriate or inconsistent data
insertion into a column.
2. Referential Integrity Constraint
The referential integrity constraint establishes relationships between tables by enforcing
consistency in related data. It ensures that one table’s values in a foreign key column(s)
correspond to the primary key values in another table. This constraint prevents the
creation of orphaned records and maintains the integrity of data associations between
tables.
3. Entity Integrity Constraint
The entity integrity constraint focuses on the uniqueness of primary key values within a
table. It ensures that a table’s primary key column(s) contains unique and non-null values.

NIMS BCA DEPT DBMS NOTES Page 4


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

This constraint guarantees the identification and differentiation of individual records


within a table.
4. Key Constraint
The key constraint determines the uniqueness of values within a column or a combination
of columns. It can be applied to designate a candidate key or a primary key. The key
constraint prevents duplicate values in the specified column(s) and ensures that each
record can be uniquely identified. Here are the types of key constraints:
5. NOT NULL Constraint
The NOT NULL constraint specifies that a column in a table must not contain any null
values. It ensures that a particular attribute or field cannot be left empty or undefined for
any record in the table.
6. UNIQUE Constraint
The UNIQUE constraint ensures that the values in a specific column(s) are unique across
all the records in a table. It allows for the insertion of null values. However, it allows only
one instance of a non-null value.
7. PRIMARY KEY Constraint
The PRIMARY KEY constraint identifies each record in a table uniquely. It enforces the
uniqueness and non-null property of one or more columns in a table. A primary key can
consist of a single column or a combination of multiple columns.
8. FOREIGN KEY Constraint
The FOREIGN KEY constraint creates a relationship between two tables based on the
values of a column or columns. It helps maintain referential integrity by enforcing that the
values in a specific column(s) of one table correspond to those of a primary key in another
table.
9. CHECK Constraint
The CHECK constraint explains a condition that must be satisfied for the values in a
column(s). It allows you to limit the range of acceptable values based on a specific condition
or expression.

Relational Algebra

Relational Algebra refers to a procedural query language that accepts a Relation as input and
outputs another Relation. Theoretical foundations for relational databases and SQL are provided
by relational algebra

These are the basic/fundamental operators used in Relational Algebra.


1. Selection(σ)
2. Projection(π)
3. Union(U)
4. Set Difference(-)
5. Set Intersection(∩)
6. Rename(ρ)
7. Cartesian Product(X)

NIMS BCA DEPT DBMS NOTES Page 5


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

1. Selection(σ): It is used to select required tuples of the relations.


Example:
A B C

1 2 4

2 2 3

3 2 3

4 3 4
For the above relation, σ(c>3)R will select the tuples which have c more than 3.
A B C

1 2 4

4 3 4
Note: The selection operator only selects the required tuples but does not display them. For
display, the data projection operator is used.

2. Projection(π): It is used to project required column data from a relation.

Example: Consider Table 1. Suppose we want columns B and C from Relation R.


π(B,C)R will show following columns.
B C

2 4

2 3

3 4
Note: By Default, projection removes duplicate data.

NIMS BCA DEPT DBMS NOTES Page 6


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

3. Union(U): Union operation in relational algebra is the same as union operation in set theory.
Example:
FRENCH
Student_Name Roll_Number

Ram 01

Mohan 02

Vivek 13

Geeta 17
GERMAN
Student_Name Roll_Number

Vivek 13

Geeta 17

Shyam 21

Rohan 25
Consider the following table of Students having different optional subjects in their course.
π(Student_Name)FRENCH U π(Student_Name)GERMAN
Student_Name

Ram

Mohan

Vivek

Geeta

Shyam

Rohan

NIMS BCA DEPT DBMS NOTES Page 7


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Note: The only constraint in the union of two relations is that both relations must have the
same set of Attributes.

4. Set Difference(-): Set Difference in relational algebra is the same set difference operation as
in set theory.

Example: From the above table of FRENCH and GERMAN, Set Difference is used as follows
π(Student_Name)FRENCH - π(Student_Name)GERMAN
Student_Name

Ram

Mohan
Note: The only constraint in the Set Difference between two relations is that both relations
must have the same set of Attributes.

5. Set Intersection(∩): Set Intersection in relational algebra is the same set intersection
operation in set theory.

Example: From the above table of FRENCH and GERMAN, the Set Intersection is used as
follows
π(Student_Name)FRENCH ∩ π(Student_Name)GERMAN
Student_Name

Vivek

Geeta
Note: The only constraint in the Set Difference between two relations is that both relations
must have the same set of Attributes.

6. Rename(ρ): Rename is a unary operation used for renaming attributes of a relation.


ρ(a/b)R will rename the attribute 'b' of the relation by 'a'.

7. Cross Product(X): Cross-product between two relations. Let’s say A and B, so the cross
product between A X B will result in all the attributes of A followed by each attribute of B.
Each record of A will pair with every record of B.

NIMS BCA DEPT DBMS NOTES Page 8


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Example:
A
Name Age Sex

Ram 14 M

Sona 15 F

Kim 20 M
B
ID Course

1 DS

2 DBMS
AXB
Name Age Sex ID Course

Ram 14 M 1 DS

Ram 14 M 2 DBMS

Sona 15 F 1 DS

Sona 15 F 2 DBMS

Kim 20 M 1 DS

Kim 20 M 2 DBMS
Note: If A has ‘n’ tuples and B has ‘m’ tuples then A X B will have ‘ n*m ‘ tuples.

NIMS BCA DEPT DBMS NOTES Page 9


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Set Theory Operators-


Following operators are called as set theory operators-

Union Operator (∪)


Intersection Operator (∩)
Difference Operator (-)

1. Union Operator (∪)-

Let R and S be two relations.


Then-
R ∪ S is the set of all tuples belonging to either R or S or both.
In R ∪ S, duplicates are automatically removed.
Union operation is both commutative and associative.

Example-

Consider the following two relations R and S-

ID Name Subject

100 Ankit English

200 Pooja Maths

300 Komal Science


Relation R

ID Name Subject

100 Ankit English

400 Kajol French


Relation S

NIMS BCA DEPT DBMS NOTES Page 10


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Then, R ∪ S is-

ID Name Subject

100 Ankit English

200 Pooja Maths

300 Komal Science

400 Kajol French


Relation R ∪ S

2. Intersection Operator (∩)-

Let R and S be two relations.


Then-
R ∩ S is the set of all tuples belonging to both R and S.
In R ∩ S, duplicates are automatically removed.
Intersection operation is both commutative and associative.

Example-

Consider the following two relations R and S-

ID Name Subject

100 Ankit English

200 Pooja Maths

300 Komal Science


Relation R

ID Name Subject

100 Ankit English

400 Kajol French


Relation S

NIMS BCA DEPT DBMS NOTES Page 11


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Then, R ∩ S is-

ID Name Subject

100 Ankit English


Relation R ∩ S

3. Difference Operator (-)-

Let R and S be two relations.


Then-
R – S is the set of all tuples belonging to R and not to S.
In R – S, duplicates are automatically removed.
Difference operation is associative but not commutative.

Example-
Consider the following two relations R and S-

ID Name Subject

100 Ankit English

200 Pooja Maths

300 Komal Science


Relation R

ID Name Subject

100 Ankit English

400 Kajol French


Relation S

Then, R – S is-

ID Name Subject

200 Pooja Maths

300 Komal Science


Relation R – S

NIMS BCA DEPT DBMS NOTES Page 12


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

JOINS

Join is an operation in DBMS(Database Management System) that combines the row of two or
more tables based on related columns between them. The main purpose of Join is to retrieve
the data from multiple tables in other words Join is used to perform multi-table query. It is
denoted by ⨝.
Syntax
R3 <- ⨝(R1) <join_condition> (R2)
where R1 and R2 are two relations to be join and R3 is a relation that will holds the result of
join operation.

Example
Temp <- ⨝(student) S.roll==E.roll(Exam)
where S and E are alias of the student and exam respectively

Types of Join
1. Inner Join
2. Outer join
3. Inner join

1, Inner Join is a join operation in DBMS that combines two or more table based on related
columns and return only rows that have matching values among tables.Inner join of two types.
1. Equi Join
2. Natural Join

Equi Join
Equi Join is a type of Inner join in which we use euivalence(‘=’) condition in join condition
Example:
Table A
Column A Column B

a a

a b
Table B
Column A Column B

a a

a c
A ⨝ A.Column B = B.Column B (B)

NIMS BCA DEPT DBMS NOTES Page 13


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Result:
Column A Column B

a a

Natural Join
Natural join is a type of inner join in which we not need of any comparison operators. In
natural join columns should have the same name and domain. There should be at least one
common attribute between two tables.
Eample:
Table A
Number Square

2 4

3 9
Table B
Number Cube

2 8

3 27
A⨝B
Number Square Cube

2 4 8

3 9 27

Outer Join
Outer join is a type of join that retrieve matching as well as non-maching records from related
tables.
There three types of outer join
1. Left outer join
2. Right outer join
3. Full outer join
4. Left Outer Join
It is also called left join. This type of outer join retrieve all records from left table and retrive
maching record from right table.

NIMS BCA DEPT DBMS NOTES Page 14


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Example:
Table A
Number Square

2 4

3 9

4 16
Table B
Number Cube

2 8

3 27

5 75
A⟕B
Result:
Number Square Cube

2 4 8

3 9 27

4 16 –

Right Outer Join


It is also called right join. This type of outer join retrieve all records from right table and
retrive maching record from right table.
Example:
Table A and Table B are same as in left outer join
A⟖B
Number Square Cube

2 4 8

3 9 27

NIMS BCA DEPT DBMS NOTES Page 15


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Number Square Cube

5 – 75

Full Outer Join


In full outer join all the rows from both table are inserted in result table
Eaxmple:
Table A and Table B are same as in left outer join
A⟗B
Result:
Number Square Cube

2 4 8

3 9 27

4 16 –

5 – 75

Aggregate Functions and Grouping


Group functions are built in SQL functions. That operators on group of rows and return one
value
for the entire group or table.
• The SQL aggregate functions return a single value calculated from values in a column.
• They are used to produce summarized results.
Types:
1. Sum()
2. Avg()
3. Min()
4. Max()
5. Count()

Example: Employee
EmpId Empname Empsal
1001 sundar 25000
1002 manoj 20000
1003 Bharath 10000
1004 Prakash 5000
1005 Shreedhar 100000

NIMS BCA DEPT DBMS NOTES Page 16


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

1) Sum():This function is used to get the sum of numerical column.


Syntax: select sum(col-list) from table name;
Example: select sum(emp sal) from employee;
Sum(emp sal)
160000

2) Avg(): This function is used to get the avg of numerical column.


Syntax: select avg(col-list) from table name;
Example: select avg(emp sal) from employee;
Avg(emp sal)
320000

3) Max(): This function is used to check the maximum value of numerical column.
Syntax: select max(col-list) from table name;
Example: select max(emp sal) from employee;
Max(emp sal)
100000

4)Min():This function is used to check the minimum value of numerical column.


Syntax: select min(col-list) from table name;
Example: select min(emp sal) from employee;
Min(emp sal)
5000

5) Count():
• This function is used to return the number of records in the table.)
Syntax: select count(exp) from <table name>where<condition>;
Example: select count(emp sal) from employee;
Count(emp sal)
5

Views
View is a virtual table based on one or more tables.
• A view can be created from one or more tables which depends on the writtens SQL query to
create a
view.
• A view can contain all rows of a table/selected rows from a table.
• Most of the operations that can be carried on the table can be carried out on view.
• Any updating of rows in a table will automatically reflect in the veiewtable.
Syntax: Create view<view name>as select<col-list>from<tablename>where<condition>;
Student
Rno Name Total
1 anu 700
2 ashu 900
3 chinnu 850

NIMS BCA DEPT DBMS NOTES Page 17


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

4 priya 700
5 Chitti 680

Example: Create view studentview as select Rno, Name from Student;


Rno Name
1 anu
2 ashu
3 chinnu
4 priya
5 Chitti

Nested Subquery: An SQL query that has another query enclosed in its WHERE, FROM, or
SELECT clause.
Example:SELECT product_name, priceFROM productsWHERE price > (SELECT AVG(price)
FROM products);

PL/SQL(intro,charecteristics,features)

1. PL/SQL is basically a procedural language, which provides the functionality of decision


making, iteration and many more features of procedural programming languages.
2. PL/SQL can execute a number of queries in one block using single command.
3. One can create a PL/SQL unit such as procedures, functions, packages, triggers, and types,
which are stored in the database for reuse by applications.
4. PL/SQL provides a feature to handle the exception which occurs in PL/SQL block known
as exception handling block.
5. Applications written in PL/SQL are portable to computer hardware or operating system
where Oracle is operational.
6. PL/SQL Offers extensive error checking.

Differences between SQL and PL/SQL:


SQL PL/SQL

PL/SQL is a block of codes that used to write


SQL is a single query that is used to perform
the entire program blocks/ procedure/ function,
DML and DDL operations.
etc.

It is declarative, that defines what needs to be PL/SQL is procedural that defines how the
done, rather than how things need to be done. things needs to be done.

Execute as a single statement. Execute as a whole block.

Mainly used to manipulate data. Mainly used to create an application.

NIMS BCA DEPT DBMS NOTES Page 18


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

It is an extension of SQL, so it can contain SQL


Cannot contain PL/SQL code in it.
inside it.

Structure of PL/SQL Block:

structure:
DECLARE
declaration statements;
BEGIN
executable statements
EXCEPTIONS
exception handling statements
END;

1. Declare section starts with DECLARE keyword in which variables, constants, records as
cursors can be declared which stores data temporarily. It basically consists definition of
PL/SQL identifiers. This part of the code is optional.
2. Execution section starts with BEGIN and ends with END keyword.This is a mandatory
section and here the program logic is written to perform any task like loops and conditional
statements. It supports all DML commands, DDL commands and SQL*PLUS built-in
functions as well.
3. Exception section starts with EXCEPTION keyword.This section is optional which
contains statements that are executed when a run-time error occurs. Any exceptions can be
handled in this section.

--PL/SQL code to print sum of two numbers taken from the user.

DECLARE
a integer := &a
b integer := &b ;
c integer ;
BEGIN
c := a + b ;
dbms_output.put_line('Sum of '||a||' and '||b||' is = '||c);
END;
/
Oiutput
Enter value for a: 2
Enter value for b: 3

Sum of 2 and 3 is = 5

PL/SQL procedure successfully completed.

NIMS BCA DEPT DBMS NOTES Page 19


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

UNIT 4 DATA NORMALIZATION

Anomalies : means problems or inconsistency which happened during the operations performed
on the table. There can be many reasons that anomaly occur for example,It occurs when data is
stored multiple times unnecessarily in the database i.e. redundant data is present or it occur when
all the data is stored in a single table. normalization is used to overcome the anomalies.
Example
Consider a manufacturing firm that keeps worker information in a table called employee, which
has four columns: w_id for the employee’s id, w_name for the employee’s name, w_address for
the employee’s address, and w_dept for the employee’s department. The table will look like this
at some point:
w_id w_name w_address w_dept
201 David Delhi F001
201 David Delhi F002
223 Mike Agra F890
266 Berry Chennai F900
266 Berry Chennai F004
The table above has not been normalized. We’ll look at the issues that arise when the table isn’t
normalized.

Type of Anomalies
1. Update
2. Insert
3. Delete

1. Update Anomaly
Employee David has two rows in the table given above since he works in two different
departments. If we want to change David’s address, we must do so in two rows, else the data
would become inconsistent.
If the proper address is updated in one of the departments but not in another, David will have two
different addresses in the database, which is incorrect and leads to inconsistent data.

2. Insert Anomaly If a new worker joins the firm and is currently unassigned to any
department, we will be unable to put the data into the table because the w_dept field does not
allow nulls.

3. Delete Anomaly: If the corporation closes the department F890 at some point in the future,
deleting the rows with w_dept as F890 will also erase the information of employee Mike, who is
solely assigned to this department.

NIMS BCA DEPT DBMS NOTES Page 1


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Decomposition The process of breaking up or dividing a single relation into two or more sub
relations is called as decomposition of a relation.

1. Lossless Decomposition - Decomposition is lossless if it is feasible to reconstruct


relation R from decomposed tables using Joins. This is the preferred choice. The
information will not lose from the relation when decomposed. The join would result in
the same original relation.

Let us see an example −<EmpInfo>


Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E002 Henry 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt3 Finance

Decompose the above table into two tables:


<EmpDetails>
Emp_ID Emp_Name Emp_Age Emp_Location
E001 Jacob 29 Alabama
E002 Henry 32 Alabama
E003 Tom 22 Texas

<DeptDetails>
Dept_ID Emp_ID Dept_Name
Dpt1 E001 Operations
Dpt2 E002 HR
Dpt3 E003 Finance

Now, Natural Join is applied on the above two tables −


The result will be −
Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E002 Henry 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt3 Finance
Therefore, the above relation had lossless decomposition i.e. no loss of information.

2. Lossy Decomposition- As the name suggests, when a relation is decomposed into two or
more relational schemas, the loss of information is unavoidable when the original relation
is retrieved.

NIMS BCA DEPT DBMS NOTES Page 2


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Let us see an example −


<EmpInfo>
Emp_ID Emp_Name Emp_Age Emp_Location Dept_ID Dept_Name
E001 Jacob 29 Alabama Dpt1 Operations
E002 Henry 32 Alabama Dpt2 HR
E003 Tom 22 Texas Dpt3 Finance

Decompose the above table into two tables −


<EmpDetails>
Emp_ID Emp_Name Emp_Age Emp_Location
E001 Jacob 29 Alabama
E002 Henry 32 Alabama
E003 Tom 22 Texas

<DeptDetails>
Dept_ID Dept_Name
Dpt1 Operations
Dpt2 HR
Dpt3 Finance
Now, you won’t be able to join the above tables, since Emp_ID isn’t part of
the DeptDetails relation.
Therefore, the above relation has lossy decomposition.

Functional Dependency

The functional dependency is a relationship that exists between two attributes. It typically exists
between the primary key and non-key attribute within a table.
X → Y
The left side of FD is known as a determinant, the right side of the production is known as a
dependent.
For example:
Assume we have an employee table with attributes: Emp_Id, Emp_Name, Emp_Address.Here
Emp_Id attribute can uniquely identify the Emp_Name attribute of employee table because if we
know the Emp_Id, we can tell that employee name associated with it.
Functional dependency can be written as:
Emp_Id → Emp_Name
We can say that Emp_Name is functionally dependent on Emp_Id.

NIMS BCA DEPT DBMS NOTES Page 3


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Types of Functional dependency

1. Trivial functional dependency


A → B has trivial functional dependency if B is a subset of A.
The following dependencies are also trivial like: A → A, B → B
Example:
Consider a table with two columns Employee_Id and Employee_Name.
{Employee_id, Employee_Name} → Employee_Id is a trivial functional dependency as
Employee_Id is a subset of {Employee_Id, Employee_Name}.
Also, Employee_Id → Employee_Id and Employee_Name → Employee_Name are trivial de
pendencies too.

2. Non-trivial functional dependency


A → B has a non-trivial functional dependency if B is not a subset of A.
When A intersection B is NULL, then A → B is called as complete non-trivial.
Example:
ID → Name,
Name → DOB

Normalization

1. Normalization is the process of organizing the data in the database.


2. Normalization is used to minimize the redundancy from a relation or set of relations. It is
also used to eliminate undesirable characteristics like Insertion, Update, and Deletion
Anomalies.
3. Normalization divides the larger table into smaller and links them using relationships.
4. The normal form is used to reduce redundancy from the database table.

NIMS BCA DEPT DBMS NOTES Page 4


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Types of Normalization

Normal Description
Form

1NF A relation is in 1NF if it contains an atomic value.

2NF A relation will be in 2NF if it is in 1NF and all non-key attributes are fully
functional dependent on the primary key.

3NF A relation will be in 3NF if it is in 2NF and no transition dependency


exists.

BCNF A stronger definition of 3NF is known as Boyce Codd's normal form.

4NF A relation will be in 4NF if it is in Boyce Codd's normal form and has no
multi-valued dependency.

5NF A relation is in 5NF. If it is in 4NF and does not contain any join
dependency, joining should be lossless.

Advantages of Normalization
1. Normalization helps to minimize data redundancy.
2. Greater overall database organization.
3. Data consistency within the database.
4. Much more flexible database design.
5. Enforces the concept of relational integrity.
Disadvantages of Normalization
1. You cannot start building the database before knowing what the user needs.
2. The performance degrades when normalizing the relations to higher normal forms, i.e.,
4NF, 5NF.
3. It is very time-consuming and difficult to normalize relations of a higher degree.
4. Careless decomposition may lead to a bad database design, leading to serious problems.

First Normal Form (1NF)


1. A relation will be 1NF if it contains an atomic value.
2. It states that an attribute of a table cannot hold multiple values. It must hold only single-
valued attribute.
3. First normal form disallows the multi-valued attribute, composite attribute, and their
combinations.

NIMS BCA DEPT DBMS NOTES Page 5


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Example: Relation EMPLOYEE is not in 1NF because of multi-valued attribute EMP_PHONE.


EMPLOYEE table:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385, UP
9064738238

20 Harry 8574783832 Bihar

12 Sam 7390372389, Punjab


8589830302
The decomposition of the EMPLOYEE table into 1NF has been shown below:
EMP_ID EMP_NAME EMP_PHONE EMP_STATE

14 John 7272826385 UP

14 John 9064738238 UP

20 Harry 8574783832 Bihar

12 Sam 7390372389 Punjab

12 Sam 8589830302 Punjab

Second Normal Form (2NF)


1. In the 2NF, relational must be in 1NF.
2. In the second normal form, all non-key attributes are fully functional dependent on the
primary key
Example: Let's assume, a school can store the data of teachers and the subjects they teach. In a
school, a teacher can teach more than one subject.
TEACHER table
TEACHER_ID SUBJECT TEACHER_AGE

25 Chemistry 30

25 Biology 30

47 English 35

83 Math 38

83 Computer 38

NIMS BCA DEPT DBMS NOTES Page 6


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

In the given table, non-prime attribute TEACHER_AGE is dependent on TEACHER_ID which


is a proper subset of a candidate key. That's why it violates the rule for 2NF.

To convert the given table into 2NF, we decompose it into two tables:
TEACHER_DETAIL table:
TEACHER_ID TEACHER_AGE

25 30

47 35

83 38

TEACHER_SUBJECT table:
TEACHER_ID SUBJECT

25 Chemistry

25 Biology

47 English

83 Math

83 Computer

Third normal form


1. A relation will be in 3NF if it is in 2NF and not contain any transitive partial dependency.
2. 3NF is used to reduce the data duplication. It is also used to achieve the data integrity.
3. If there is no transitive dependency for non-prime attributes, then the relation must be in
third normal form.
A relation is in third normal form if it holds atleast one of the following conditions for every
non-trivial function dependency X → Y.
X is a super key.
Y is a prime attribute, i.e., each element of Y is part of some candidate key.

NIMS BCA DEPT DBMS NOTES Page 7


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Example:
EMPLOYEE_DETAIL table:
EMP_ID EMP_NAME EMP_ZIP EMP_STATE EMP_CITY

222 Harry 201010 UP Noida

333 Stephan 02228 US Boston

444 Lan 60007 US Chicago

555 Katharine 06389 UK Norwich

666 John 462007 MP Bhopal


Super key in the table above:
{EMP_ID}, {EMP_ID, EMP_NAME}, {EMP_ID, EMP_NAME, EMP_ZIP}....so on

Candidate key: {EMP_ID}


Non-prime attributes: In the given table, all attributes except EMP_ID are non-prime.
Here, EMP_STATE & EMP_CITY dependent on EMP_ZIP and EMP_ZIP dependent on
EMP_ID. The non-prime attributes (EMP_STATE, EMP_CITY) transitively dependent on super
key(EMP_ID). It violates the rule of third normal form.
That's why we need to move the EMP_CITY and EMP_STATE to the new <EMPLOYEE_ZIP>
table, with EMP_ZIP as a Primary key

EMPLOYEE table:
EMP_ID EMP_NAME EMP_ZIP

222 Harry 201010

333 Stephan 02228

444 Lan 60007

555 Katharine 06389

666 John 462007

NIMS BCA DEPT DBMS NOTES Page 8


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

EMPLOYEE_ZIP table:

EMP_ZIP EMP_STATE EMP_CITY

201010 UP Noida

02228 US Boston

60007 US Chicago

06389 UK Norwich

462007 MP Bhopal

Boyce Codd normal form (BCNF)


1. BCNF is the advance version of 3NF. It is stricter than 3NF.
2. A table is in BCNF if every functional dependency X → Y, X is the super key of the
table.
3. For BCNF, the table should be in 3NF, and for every FD, LHS is super key.
4.
Example: Let's assume there is a company where employees work in more than one department.

EMPLOYEE table:
EMP_ID EMP_COUNTRY EMP_DEPT DEPT_TYPE EMP_DEPT_NO

264 India Designing D394 283

264 India Testing D394 300

364 UK Stores D283 232

364 UK Developing D283 549

In the above table Functional dependencies are as follows:


EMP_ID → EMP_COUNTRY
EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate key: {EMP-ID, EMP-DEPT}

The table is not in BCNF because neither EMP_DEPT nor EMP_ID alone are keys.
To convert the given table into BCNF, we decompose it into three tables:

NIMS BCA DEPT DBMS NOTES Page 9


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

EMP_COUNTRY table:
EMP_ID EMP_COUNTRY

264 India

264 India

EMP_DEPT table:
EMP_DEPT DEPT_TYPE EMP_DEPT_NO

Designing D394 283

Testing D394 300

Stores D283 232

Developing D283 549

EMP_DEPT_MAPPING table:
EMP_ID EMP_DEPT

D394 283

D394 300

D283 232

D283 549

Functional dependencies:
EMP_ID → EMP_COUNTRY
EMP_DEPT → {DEPT_TYPE, EMP_DEPT_NO}
Candidate keys:
For the first table: EMP_ID
For the second table: EMP_DEPT
For the third table: {EMP_ID, EMP_DEPT}
Now, this is in BCNF because left side part of both the functional dependencies is a key.

NIMS BCA DEPT DBMS NOTES Page 10


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

TRANSACTION :

1. A transaction is a logical unit of work of database processing that includes one or more
database access operations.
2. . A transaction can be defined as an action or series of actions that is carried out by a single
user or application program to perform operations for accessing the contents of the database.
The operations can include retrieval, (Read), insertion (Write), deletion and modification. A
transaction must be either completed or aborted
3. It can either be embedded within an application program or can be specified interactively via
a high-level query language such as SQL. Its execution preserves the consistency of the
database.Each transaction should access shared data without interfering with the other
transactions and whenever a transaction successfully completes its execution; its effect
should be permanent.

This basic abstraction frees the database application programmer from the following
concerns :
1. Inconsistencies caused by conflicting updates from concurrent users.
2. Partially completed transactions in the event of systems failure.
3. User-directed undoing of transactions.

A transaction is a sequence of READ and WRITE actions that are grouped together to from a
database access. A transaction may consist of a simple SELECT operation to generate a list of
table contents, or it may consist of a series of related UPDATE command sequences.

A transaction can include the following basic database access operations:


Operations Descriptions

Retrive To retrive data stored ina database.

Insert To store new data in database.

Delete To delete existing data from database.

Update To modify existing data in database.

Commit To save the work done permanently.

Rollback To undo the work done.

Transaction that changes the contents of the database must alter the database from
one consistent state to another. A consistent database state is one in which all data integrity
constraints are satisfied.
To ensure database consistency, every transaction must begin with the database in a known
consistent state.

NIMS BCA DEPT UNIT5 NOTES Page 1


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

SINGLE USER SYSTEM:

❖ A single user system in DBMS refers to a database management system that allows only one
user to access and manipulate the database at a time. In other words, a single user system
provides exclusive access to the database, and no other user can make any changes or
modifications to the data until the first user has finished.
❖ These systems are typically used in small organizations.

Example: Personal computer


• Allow only one user to access the database at a time.
• Typically used in small organizations or personal settings
where there is low demand for concurrent access to the
database.
• Suitable for simple database applications, where only one
person needs to access the data.

Advantages of single user:


• Simplicity: Single-user DBMS is easy to use and manage, as it doesn't require multiple users to
access the data simultaneously.
• Cost-effective: Single-user DBMS is cost-effective compared to multi-user DBMS as it
requires fewer resources and hardware.

Disadvantages of single user:


• Limited accessibility: Only one person can access the data, making it difficult for multiple
users to collaborate and work on the same data simultaneously.
• Scalability: Single-user DBMS is not designed to handle large amounts of data and multiple
users, making it unsuitable for organizations that need to scale up their operations.
• Data sharing: Data sharing between multiple users is not possible in single-user DBMS, making
it difficult to work with others who may need access to the same data.

MULTI USER SYSTEM:

❖ A multi-user system in DBMS is a database management system that allows multiple users to
access and manipulate the database simultaneously. In this type of system, multiple users can
perform different operations on the database at the same time, such as adding, modifying or
deleting data. The system is designed to manage concurrent access and ensure data consistency,
so that multiple users can work on the same database without conflicting with each other.

Example: supermarkets, DataBase of banks


❖ Allow multiple users to access and manipulate the database simultaneously.
❖ Typically used in large organizations or multi-departmental settings where multiple users
need to access the same database for their work.
❖ Suitable for complex database applications where multiple users need to access and update
the data simultaneously.

NIMS BCA DEPT UNIT5 NOTES Page 2


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Advantages of Multi users:

• Collaboration: Multi-user DBMS allows multiple users to access the same data simultaneously,
making it easier for teams to work together and collaborate on projects.
• Scalability: Multi-user DBMS is designed to handle large amounts of data and multiple users,
making it suitable for organizations that need to scale up their operations.
• Data sharing: Multi-user DBMS makes it possible for multiple users to access and share data,
allowing for better data sharing and collaboration between team members.

Disadvantages of Multi users:


• Complexity: Multi-user DBMS is generally more complex to manage than single-user DBMS,
as it requires more resources and hardware.
• Cost: Multi-user DBMS can be more expensive than single-user DBMS, as it requires more
resources and hardware.
• Performance issues: Multi-user DBMS can experience performance issues, such as slow
response times, if too many users are accessing the system simultaneously.

READ AND WRITE OPERATIONS

Basic unit of data transfer from the disk to the computer main memory is one disk block

read_item(X) includes the following steps:


1. Find the address of the disk block that contains item X.
2. Copy that disk block into a buffer in main memory (if that disk block is not already in some
main memory buffer).
3. Copy item X from the buffer to the program variable named X.

write_item(X) includes the following steps:


1. Find the address of the disk block that contains item X.
2. Copy that disk block into a buffer in main memory (if it is not already in some main memory
buffer).
3. Copy item X from the program variable named X into its correct location in the buffer.
4. Store the updated block from the buffer back to disk • either immediately or, more typically, at
some later point in time

NEED OF CONCURRENCY CONTROL

Concurrency:Executing multiple transactions at a time is called concurrency.

The three main problems of concurrency are:


1)LOST UPDATE.
2)UNCOMMITTED DATA (OR) DIRTY READ PROBLEM. and many others

NIMS BCA DEPT UNIT5 NOTES Page 3


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

LOST UPDATE PROBLEM:

A lost update problem occurs due to the update of the same record by two different transactions at
the same time.
In simple words, when two transactions are updating the same record at the same time in a DBMS
then a lost update problem occurs. The first transaction updates a record and the second
transaction updates the same record again, which nullifies the update of the first transaction. As
the update by the first transaction is lost this concurrency problem is known as the lost update
problem.

What Are the Different Ways to Prevent Lost Updates?

Increase Transaction Isolation Level


Increasing the isolation level of transactions on a database is one of the ways to prevent lost
update problems. Isolation is I in ACID properties.
Optimistic Locking
Optimistic locking is the most common method used to prevent lost update problems. This
method allows any update of a record to happen only when the value of that record has not
changed after its last read.
Atomic write operations
One of the many ways to prevent lost update problems is Atomic write operations. Atomic write
operations read records at a memory location and write a new value into it simultaneously.
Atomic write operations remove the need to implement read-modify-write cycles repeatedly.

DIRTY READ PROBLEM


The dirty read problem in DBMS occurs when a transaction reads the data that has been updated
by another transaction that is still uncommitted. It arises due to multiple uncommitted transactions
executing simultaneously.

NIMS BCA DEPT UNIT5 NOTES Page 4


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Example: Consider two transactions A and B performing read/write operations on a data DT in


the database DB. The current value of DT is 1000: The following table shows the read/write
operations in A and B transactions.

Transaction A reads the value of data DT as 1000 and modifies it to 1500 which gets stored in the
temporary buffer. The transaction B reads the data DT as 1500 and commits it and the value of
DT permanently gets changed to 1500 in the database DB. Then some server errors occur in
transaction A and it wants to get rollback to its initial value, i.e., 1000 and then the dirty read
problem occurs.

TYPES OF FAILURES:
Failures are generally classified as transaction, system, and media failures. There are several
possible reasons for a transaction to fail in the middle of execution:

• A computer failure (system crash): A hardware, software, or network error occurs in the
computer system during transaction execution. Hardware crashes are usually media failuresfor
example, main memory failure.
• A transaction or system error: Some operation in the transaction may cause it to fail, such as
integer overflow or division by zero. Transaction failure may also occur because of erroneous
parameter values or because of a logical programming error.' In addition, the user may interrupt
the transaction during its execution.
• Local errors or exception conditions detected by the transaction: During transaction
execution, certain conditions may occur that necessitate cancellation of the transaction. For
example, data for the transaction may not be found. Notice that an exception condition," such as
insufficient account balance in a banking database, may cause a transaction, such as a fund
withdrawal, to be canceled. This exception should be programmed in the transaction itself, and
hence would not be considered a failure.
• Concurrency control enforcement: The concurrency control method may decide to abort the
transaction, to be restarted later, because it violates serializability or because several transactions
are in a state of deadlock.
• Disk failure: Some disk blocks may lose their data because of a read or write malfunction or
because of a disk read/write head crash. This may happen during a read or a write operation of
the transaction.

NIMS BCA DEPT UNIT5 NOTES Page 5


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

• Physical problems and catastrophes: This refers to an endless list of problems that includes
power or air-conditioning failure, fire, theft, sabotage, overwriting disks or tapes by mistake, and
mounting of a wrong tape by the operator.

STATES OF TRANSACTION

In a database, the transaction can be in one of the following states -

Active state
The active state is the first state of every transaction. In this state, the transaction is being
executed.
For example: Insertion or deletion or updating a record is done here. But all the records are still
not saved to the database.
Partially committed
In the partially committed state, a transaction executes its final operation, but the data is still not
saved to the database.
In the total mark calculation example, a final display of the total marks step is executed in this
state.
Committed
A transaction is said to be in a committed state if it executes all its operations successfully. In
this state, all the effects are now permanently saved on the database system.
Failed state
If any of the checks made by the database recovery system fails, then the transaction is said to be
in the failed state.
In the example of total mark calculation, if the database is not able to fire a query to fetch the
marks, then the transaction will fail to execute.

NIMS BCA DEPT UNIT5 NOTES Page 6


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Aborted
If any of the checks fail and the transaction has reached a failed state then the database recovery
system will make sure that the database is in its previous consistent state. If not then it will abort
or roll back the transaction to bring the database into a consistent state.
If the transaction fails in the middle of the transaction then before executing the transaction, all
the executed transactions are rolled back to its consistent state.
After aborting the transaction, the database recovery module will select one of the two
operations:
Re-start the transaction
Kill the transaction

DESIRABLE PROPERTIES (ACID PROPERTIES):


Atomicity:
By this, we mean that either the entire transaction takes place at once or doesn’t happen at all.
There is no midway i.e. transactions do not occur partially. Each transaction is considered as
one unit and either runs to completion or is not executed at all. It involves the following two
operations.
—Abort: If a transaction aborts, changes made to the database are not visible.
—Commit: If a transaction commits, changes made are visible.
Atomicity is also known as the ‘All or nothing rule’.

Consider the following transaction T consisting of T1 and T2: Transfer of 100 from
account X to account Y.

If the transaction fails after completion of T1 but before completion of T2.( say,
after write(X) but before write(Y)), then the amount has been deducted from X but not added
to Y. This results in an inconsistent database state. Therefore, the transaction must be executed
in its entirety in order to ensure the correctness of the database state.

Consistency:
This means that integrity constraints must be maintained so that the database is consistent
before and after the transaction. It refers to the correctness of a database. Referring to the
example above,
The total amount before and after the transaction must be maintained.
Total before T occurs = 500 + 200 = 700.
Total after T occurs = 400 + 300 = 700.
Therefore, the database is consistent. Inconsistency occurs in case T1 completes but T2 fails.
As a result, T is incomplete.

NIMS BCA DEPT UNIT5 NOTES Page 7


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Isolation:
This property ensures that multiple transactions can occur concurrently without leading to the
inconsistency of the database state. Transactions occur independently without interference.
Changes occurring in a particular transaction will not be visible to any other transaction until
that particular change in that transaction is written to memory or has been committed. This
property ensures that the execution of transactions concurrently will result in a state that is
equivalent to a state achieved these were executed serially in some order.
Let X= 500, Y = 500.
Consider two transactions T and T”.

Suppose T has been executed till Read (Y) and then T’’ starts. As a result, interleaving of
operations takes place due to which T’’ reads the correct value of X but the incorrect value
of Y and sum computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of the transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
This results in database inconsistency, due to a loss of 50 units. Hence, transactions must take
place in isolation and changes should be visible only after they have been made to the main
memory.

Durability:
This property ensures that once the transaction has completed execution, the updates and
modifications to the database are stored in and written to disk and they persist even if a system
failure occurs. These updates now become permanent and are stored in non-volatile memory.
The effects of the transaction, thus, are never lost.

LOCKS

1. Lock Based Protocols in DBMS is a mechanism in which a transaction cannot Read or


Write the data until it acquires an appropriate lock. Lock based protocols help to eliminate
the concurrency problem in DBMS for simultaneous transactions by locking or isolating a
particular transaction to a single user.
2. A lock is a data variable which is associated with a data item. This lock signifies that
operations that can be performed on the data item. Locks in DBMS help synchronize access
to the database items by concurrent transactions.
3. All lock requests are made to the concurrency-control manager. Transactions proceed only
once the lock request is granted.

NIMS BCA DEPT UNIT5 NOTES Page 8


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Binary Locks: A Binary lock on a data item can either locked or unlocked states.

Shared/exclusive: This type of locking mechanism separates the locks in DBMS based on their
uses. If a lock is acquired on a data item to perform a write operation, it is called an exclusive
lock.

1. Shared Lock (S):


A shared lock is also called a Read-only lock. With the shared lock, the data item can be shared
between transactions. This is because you will never have permission to update data on the data
item.
For example, consider a case where two transactions are reading the account balance of a
person. The database will let them read by placing a shared lock. However, if another transaction
wants to update that account’s balance, shared lock prevent it until the reading process is over.

2. Exclusive Lock (X):


With the Exclusive Lock, a data item can be read as well as written. This is exclusive and can’t
be held concurrently on the same data item. X-lock is requested using lock-x instruction.
Transactions may unlock the data item after finishing the ‘write’ operation.

For example, when a transaction needs to update the account balance of a person. You can
allows this transaction by placing X lock on it. Therefore, when the second transaction wants to
read or write, exclusive lock prevent this operation.

TIMESTAMP-BASED PROTOCOLS

1. Timestamp based Protocol in DBMS is an algorithm which uses the System Time or
Logical Counter as a timestamp to serialize the execution of concurrent transactions. The
Timestamp-based protocol ensures that every conflicting read and write operations are
executed in a timestamp order.
2. The older transaction is always given priority in this method. It uses system time to
determine the time stamp of the transaction. This is the most commonly used concurrency
protocol.
3. Lock-based protocols help you to manage the order between the conflicting transactions
when they will execute. Timestamp-based protocols manage conflicts as soon as an operation
is created.
Example:
Suppose there are there transactions T1, T2, and T3.
T1 has entered the system at time 0010
T2 has entered the system at 0020
T3 has entered the system at 0030
Priority will be given to transaction T1, then transaction T2 and lastly Transaction T3.

time stamp values :


1. Read_TS(X) :It is the largest timestamp among all the timestamps
of transactions that have successfully read item X
2. Write_TS(X) :It is the largest timestamp among all the timestamps

NIMS BCA DEPT UNIT5 NOTES Page 9


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

of transactions that have successfully written item X.


3. Read_TS(X) =TS(T) Or Write_TS(X)=TS(T), where T is the most
recent transaction that has written / read X successfully.

basic timestamp ordering protocol works as follows :

RULE 1:
1. If a transaction Ti issues a read(X) operation.
If TS(Ti) < W-timestamp(X)
Abort and Rollback T, Operation Rejected
2. If TS(Ti) >= W-timestamp(X)
Set Read(X)=Max, {RTS(A), TS (T) } and Operation executed.

RULE 2 :
1. If a transaction Ti issues a write(X) operation
If TS(Ti) < R-timestamp(X), Operation Executed
If TS(Ti) < W-timestamp(X)
Operation rejected and T rolled back.
2. Otherwise, the operation is executed.

DEADLOCK

A deadlock occurs when two or more processes need some resource to complete their execution
that is held by the other process.

In the above diagram, the process 1 has resource 1 and needs to acquire resource 2. Similarly
process 2 has resource 2 and needs to acquire resource 1. Process 1 and process 2 are in deadlock
as each of them needs the other’s resource to complete their execution but neither of them is
willing to relinquish their resources.

A deadlock will only occur if the four Coffman conditions hold true. These conditions are not
necessarily mutually exclusive. They are given as follows −
Mutual Exclusion
Mutual exclusion implies there should be a resource that can only be held by one process at a
time. This means that the resources should be non-sharable.

NIMS BCA DEPT UNIT5 NOTES Page 10


DATABASE MANAGEMENT SYSTEM-21BCA3C7DML

Hold and Wait


A process can hold multiple resources and still request more resources from other processes
which are holding them.
No preemption
A resource cannot be preempted from a process by force. A process can only release a resource
voluntarily.
Circular wait
A process is waiting for the resource held by the second process, which is waiting for the
resource held by the third process and so on, till the last process is waiting for a resource held by
the first process. This forms a circular chain.

STARVATION
Starvation occurs if a process is indefinitely postponed. This may happen if the process requires
a resource for execution that it is never alloted or if the process is never provided the processor
for some reason.

Some of the common causes of starvation are as follows −


1. If a process is never provided the resources it requires for execution because of faulty
resource allocation decisions, then starvation can occur.
2. A lower priority process may wait forever if higher priority processes constantly monopolize
the processor.
3. Starvation may occur if there are not enough resources to provide to every process as
required.
4. If random selection of processes is used then a process may wait for a long time because of
non-selection.

NIMS BCA DEPT UNIT5 NOTES Page 11

You might also like