Unit 1
Unit 1
Semester-III
Database
management
systems
(DBMS)
2
S.BHARGAVI Lecturer in Computer science
UNIT IV: Structured Query Language:
Introduction,
History of SQL Standard,
Commands in SQL,
Data Types in SQL,
Data Definition Language,
Selection Operation,
Projection Operation,
Aggregate functions,
Data Manipulation Language,
Table Modification Commands,
Join Operation,
Set Operations,
View,
Sub Query.
UNIT V: PL/SQL:
Introduction,
Shortcomings of SQL,
Structure of PL/SQL,
PL/SQL Language Elements,
Data Types,
Operators Precedence,
Control Structure,
Steps to Create a PL/SQL,
Program,
Iterative Control,
Procedure,
Function,
Database Triggers,
Types of Triggers.
3
S.BHARGAVI Lecturer in Computer science
Model question paper
Section - A
Answer any 5 question 5X5 = 25M
1. Explain disadvantages of file processing system?
2. Explain the concept of entity and entity set with suitable example.
3. Explain about various attribute classification.
4. What are the advantages of Relational algebra? Explain.
5. Explain various types of keys.
6. Explain the selection command with an example.
7. Explain sub queries.
8. Explain structure of PL/SQL.
Section - B
Answer following question 5X10 = 50M
9. a) With a neat diagram, explain the architecture of a DBMS.
(OR)
b) Explain about Data Models.
10. a) Explain about Specialization and Generalization in EER model.
(OR)
b) What is ER-Modeling? Write advantages and disadvantages of ER-Modelling.
11. a) What is Functional Dependency? Explain difference between 3NF and BCNF?
(OR)
b) What is relational model? Write about key features of relational model.
12. a) What is SQL? Explain different types of commands in SQL.
(OR)
b) What is Nested Queries? How to create them? Discuss it with relevant example.
13. a) Explain steps in creating a PL/SQL Program.
(OR)
b) Explain about Triggers and types of triggers.
4
S.BHARGAVI Lecturer in Computer science
UNIT-I
Data:
Data is defined as collection of raw or unorganized facts about a place,
person, thing or object.
Raw facts indicates that this data is not yet processed to reveal its
meaningful form.
5
S.BHARGAVI Lecturer in Computer science
Data can be represented in various forms like text, numbers, images, audio,
video, graphs, document files, etc.
EX: 1, sno, name, ram, 21, age etc.
Processing:
Processing is the manipulation of data.
(Or)
It is the actual interpretation and execution of instruction on data which is carried
out by the computer’s processing unit to obtain a result.
Manipulation:
Manipulation means changing of data from one form to another form.
Information
Information can be defined as processed data that increases the knowledge
of end user.
DATA INFORMATION
1. Raw facts. 1. Processed data.
2. Unorganized data. 2. Organized data.
3. Not useful in making 3. Useful in making decisions.
decisions.
Ex: 89, 42, 24, 32, 18, 94, 21 Ex: marks age
89 21
94 18
48 32
Knowledge:
Knowledge is what we know about a particular domain (field).
Knowledge is obtained from information in the same way as information is
derived from data.
Knowledge refers to the use of information to make decisions.
Example between data, information and knowledge.
Data -- 30000,7000,18000
Information -- Samsung ---- 30000
Redmi ---- 7000
Vivo ---- 18000
6
S.BHARGAVI Lecturer in Computer science
Knowledge -- Redmi ----7000
Need of Information:
Information is necessary for the people living in the modern world. Without proper
information it is difficult to survive.
Information is needed to
To gain knowledge.
To keep system up to date.
To know about rules and regulations of society, Gov., etc.
To arrive at a particular decision that helps in forming, running and
protecting a system.
DATA INFORMATION
Data is raw fact and figures. Information is processed form
Ex: 32 of data.
Ex: age--32
Data is not sufficient to a Information is sufficient to a
business. business.
Data is atomic level piece of Information is meaningful
information. It can be in any collection of data.
form. Ex: age and 32 are collected
together to form information.
Data does not help in decision Information help in decision
making. making.
Observations and recordings Analysis is done to obtain
are done to obtain data. information.
Input to any system may be Output after processing the
treated as data. system is information.
Difficult to understand Easy to understand.
properly.
Data may not be in order. Information must be in order.
Metadata
A Meta data is the data about the data.
Metadata in DBMS is the data (details/schema) of any other data.
Metadata is a special data that describes the characteristics or properties of
the data.
Metadata consists of name, data type, length, min, max, description, special
constraints.
Metadata allows the database designers and users understand what data
exists and what data means.
7
S.BHARGAVI Lecturer in Computer science
Metadata is generally stored in a repository.
Example for Metadata:
A simple example of metadata for a document might include a collection of
information like the author, file size, the date the document was created, and
keywords to describe the document.
Database:
Database can be defined as collection of organized and logically related data
without any redundancy stored in one place and can be accessed by
multiple users.
Database can be of any size and complexity.
Data are structured so as to be easily stored, manipulated, and retrieved by
users.
8
S.BHARGAVI Lecturer in Computer science
Training is required for all programmers and users.
DBMS:
DBMS stands for Database management system. It consists of two parts
(i) Database
(ii) Management system
Database:
Database can be treated as main building block of DBMS. Generally database
contains
Data: It is the collection of raw or unorganized facts represented in various forms
like text, numbers, images, audio, video, graphs, document files, etc
Ex: 1, sno, name, ram, 21, age
Record: It is the collection of related data items. The items can be organized and
represented as meaningful information or record.
Ex:
Sno nam age
e
1 ram 21
Table: It is the collection of related records. The columns of the table are called
fields. The rows of the table are called record or tuples. Table is also called as
relation.
Ex:
Fields
name na a
Year
Record or tuple
ramme g I
sn e
o
1 ram 21
Database: Collection of related tables makes a database.
Related tables
name nam Yearage
ram e I
ravi II
sno
1 ram 21
2 ravi 22
name addres
course
ram s
Mpcs
ravi Mccs
nam
e
ram kvr
9
S.BHARGAVI Lecturer in Computer science
ravi Rjy
Database
sno nam age Year cours addres
e e s
1 ram 21 I Mpcs kvr
2 ravi 22 II Mccs Rjy
Management system:
It is the software system used to manage database and perform various
operations like insertion, deletion, updation, retrieval.
It enables the users to store, modify and extract information from database as per
requirement.
It acts as an interface between the user and the database.
Definition of DBMS:
Database management system is defined as the software that can be used to
create a database, to insert data into database, to modify data in database, to
remove/delete data in a database and to maintain a database.
Evolution of DBMS
In recent years, two approaches to DBMS are more popular, which are
a. Object-Oriented DBMS (OODBMS) and
b. Object Relational DBMS (ORDBMS).
The sequential order of the development of DBMS is as follows:
1. Flat files – 1960s–1980s
2. Hierarchical – 1970s–1990s
3. Network – 1970s–1990s
4. Relational – 1980s–present
5. Object-oriented – 1990s–present
6. Object-relational – 1990s–present
7. Data warehousing – 1980s–present
8. Web-enabled – 1990s–present
Early 1960s.
1. Charles Bachman at GE created the first general purpose DBMS Integrated
Data Store.
2. It created the basis for the network model which was standardized by
CODASYL (Conference on Data System Language).
Late 1960s:
1. IBM developed the Information Management System (IMS).
2. IMS used an alternate model, called the Hierarchical Data Model.
In 1970:
1. Edgar Codd, from IBM created the Relational Data Model.
In 1981:
1. Codd received the Turing Award for his contributions to database theory.
2. Codd Passed away in April 2003.
In 1976:
10
S.BHARGAVI Lecturer in Computer science
1. Peter Chen presented Entity-Relationship model, which is widely used in
database design.
In 1980:
1. SQL developed by IBM, became the standard query language for databases.
SQL
was standardized by ISO.
In 1980s and 1990s:
1. IBM, Oracle, Informix and others developed powerful DBMS.
Filebased approach:
File based approach was first used to computerized manual filing system.
It is basically collection of programs that perform services to the end users.
Each program within a file based system has its own definitions and
manages its own data.
In this system a large number of files are needed to perform various tasks.
This approach to data management in which separate data files are created
and stores each application program is called traditional file approach.
11
S.BHARGAVI Lecturer in Computer science
It is possible to take faster and automatic back-up of database stored in files
of computer-based systems.
Computer systems provide functionalities to serve this purpose.it is also
possible to develop specific application program for this purpose.
2. Compactness:
It is possible to store data compactly.
3. Data Retrieval:
Computer-based systems provide enhanced data retrieval techniques to
retrieve data stored in files in easy and efficient way.
4. Editing:
It is easy to edit any information stored in computers in form of files.
Specific application programs or editing software can be used for this
purpose.
5. Remote Access:
In computer-based systems,it is possible to access data remotely.
So, to access data it is not necessary for a user to remain present at location
where these data are kept.
6. Sharing:
Data stored in files of computer-based systems can be shared among
multiple users at a same time.
15
S.BHARGAVI Lecturer in Computer science
To maximize the efficiency of the database system, you must keep your
system current.
Therefore, you must perform frequent updates and apply the latest patches
and security measures to all components.
Because database technology advances rapidly, personnel training costs
tend to be significant.
Vendor dependence. Given the heavy investment in technology and
personnel training, companies might be reluctant to change database
vendors.
As a consequence, vendors are less likely to offer pricing point advantages
to existing customers, and those customers might be limited in their choice
of database system components.
4. Frequent upgrade/replacement cycles
DBMS vendors frequently upgrade their products by adding new
functionality.
Such new features often come bundled in new upgrade versions of the
software. Some of these versions require hardware upgrades.
Not only do the upgrades themselves cost money, but it also costs money to
train database users and administrators to properly use and manage the
new features.
b. Distributed DBMS
In the distributed DBMS (DDBMS) the database and the DBMS software are
distributed over many computer sites.
These computer sites are connected via a computer network.
17
S.BHARGAVI Lecturer in Computer science
Based on data models
Hierarchical database
Here data is organized like a tree which is similar to a folder structure in
your computer system.
The hierarchy starts from the root node, connecting all the child nodes to the
parent node.
Network database
It also has a hierarchical structure, but the data is organized like a graph and
it is allowed to have more than one parent for one child record.
Example
Teachers can teach in multiple departments. This is shown below −
Relation Database
This is one of the most popular data models which is used in industries. It is
based on SQL.
Every table in a database has a key field which uniquely identifies each
record.
This type of system is the most widely used DBMS.
Relational database management system software is available for personal
computers, workstation and large mainframe systems.
For example − Oracle Database, MySQL, Microsoft SQL Server etc.
Std ID Name City
18
S.BHARGAVI Lecturer in Computer science
Std ID Name City
In the above student table Std ID, Name and city are called as attributes and their
values. Std ID is a primary key attribute which uniquely identifies each record in
the student table.
Various data models
Model:
A model is a representation of reality real world objects and events and their
association.
Data model:
Data model is defined as integrated collection of concepts that can be used to
describe the logical structure of database including data type’s relationship
between data and constraints that should apply on data.
Data modelling:
Data modelling is the process of creating data model for the data to be stored in
the database.
Components of data model:
A data model has 3 components 1. Structural part
2. Manipulative part
3. Integrity rules
Data model building blocks:
1. Entity: Anything about which data can be collected and stored.
Ex: student, teacher, employee etc.
2. Attribute: The characteristic of an entity.
Ex: name, salary, job etc.
3. Relationship: An association between two or more entities.
One-one relationship
One-many relationship
Many-one relationship
Many-many relationship
4. Constraint: A constraint is a restriction placed on data.
Types of data model:
There are so many types of data models. Some of the data models are
1. Hierarchical model
2. Network model
3. Relational model
4. Entity relation model
Hierarchical Model
Hierarchical Model was the first DBMS model.
This model organizes the data in the hierarchical tree structure.
19
S.BHARGAVI Lecturer in Computer science
The hierarchy starts from the root which has root data and then it expands
in the form of a tree adding child node to the parent node.
This model easily represents some of the real-world relationships like food
recipes, sitemap of a website etc.
Example: We can represent the relationship between the shoes present on a
shopping website in the following way:
Network Model
This model is an extension of the hierarchical model.
It was the most popular model before the relational model.
This model is the same as the hierarchical model, the only difference is that
a record can have more than one parent.
It replaces the hierarchical tree with a graph.
Example: In the example below we can see that node student has two parents
i.e. CSE Department and Library.
This was earlier not possible in the hierarchical model.
Entity-Relationship Model
Entity-Relationship Model or simply ER Model is a high-level data model
diagram.
In this model, we represent the real-world problem in the pictorial form to
make it easy for the stakeholders to understand.
It is also very easy for the developers to understand the system by just
looking at the ER diagram.
We use the ER diagram as a visual tool to represent an ER Model. ER diagram
has the following three components:
Entities: Entity is a real-world thing. It can be a person, place, or even a
concept. Example: Teachers, Students, Course, Building, Department, etc
are some of the entities of a School Management System.
Attributes: An entity contains a real-world property called attribute. This is
the characteristics of that attribute. Example: The entity teacher has the
property like teacher id, salary, age, etc.
Relationship: Relationship tells how two attributes are
related. Example: Teacher works for a department.
Example:
In the above diagram, the entities are Teacher and Department. The attributes
of Teacher entity are Teacher_Name, Teacher_id, Age, Salary and
21
S.BHARGAVI Lecturer in Computer science
Mobile_Number. The attributes of entity Department entity are Dept_id,
Dept_name. The two entities are connected using the relationship. Here, each
teacher works for a department.
Advantages of ER Model
Simple: Conceptually ER Model is very easy to build. If we know the
relationship between the attributes and the entities we can easily build the
ER Diagram for the model.
Effective Communication Tool: This model is used widely by the database
designers for communicating their ideas.
Easy Conversion to any Model: This model maps well to the relational
model and can be easily converted relational model by converting the ER
model to the table. This model can also be converted to any other model
like network model, hierarchical model etc.
Disadvantages of ER Model
No industry standard for notation: There is no industry standard for
developing an ER model. So one developer might use notations which are
not understood by other developers.
Hidden information: Some information might be lost or hidden in the ER
model. As it is a high-level view so there are chances that some details of
information might be hidden.
Relational Model
Relational Model is the most widely used model.
In this model, the data is maintained in the form of a two-dimensional
table.
All the information is stored in the form of row and columns.
The basic structure of a relational model is tables.
So, the tables are also called relations in the relational model.
Example: In this example, we have an Employee table.
22
S.BHARGAVI Lecturer in Computer science
Structural Independence: We can make changes in database structure
without changing the way to access the data. When we can make changes
to the database structure without affecting the capability to DBMS to
access the data we can say that structural independence has been
achieved.
Disadvantages of Relational Model
Hardware Overheads: For hiding the complexities and making things easier
for the user this model requires more powerful hardware computers and
data storage devices.
Bad Design: As the relational model is very easy to design and use. So the
users don't need to know how the data is stored in order to access it. This
ease of design can lead to the development of a poor database which
would slow down if the database grows.
2. Software
23
S.BHARGAVI Lecturer in Computer science
Although the most readily identified software is the DBMS itself, to make the
database system function fully, three types of software are needed:
operating system software, DBMS software, and application programs and
utilities.
a. Operating system software:
• It manages all hardware components and makes it possible for all other
software to run on the computers.
Examples of operating system software include Microsoft Windows, Linux,
Macintosh OS, UNIX, and MVS.
b. DBMS software:
It manages the database within the database system.
Some examples of DBMS software include Microsoft SQL Server, Oracle
Corporation’s Oracle, Sun’s MySQL, and IBM‟s DB2.
c. Application programs and utility software:
These are used to access and manipulate data in the DBMS and to manage
the computer environment in which data access and manipulation take
place.
Application programs are most commonly used to access data found within
the database to generate reports, tabulations, and other information to
facilitate decision making.
Utilities are the software tools used to help manage the database system‟s
computer components.
For example, all of the major DBMS vendors now provide graphical user interfaces
(GUIs) to help create database structures, control database access, and monitor
database operations.
3. DBMS users
This component includes all DBMS users.
On the basis of primary job functions, five types of users can be identified in
a database system:
System administrators, database administrators, database designers,
system analysts and programmers, and end users.
Each user type, described below, performs both unique and complementary
functions. –
System administrators oversee the database system’s general operations.
Database administrators, also known as DBAs, manage the DBMS and
ensure that the database is functioning properly.
Database designers design the database structure.
They are, in effect, the database architects.
If the database design is poor, even the best application programmers and
the most dedicated DBAs cannot produce a useful database environment.
Because organizations strive to optimize their data resources, the database
designer’s job description has expanded to cover new dimensions and
growing responsibilities.
System analysts and programmers design and implement the application
programs.
They design and create the data entry screens, reports, and procedures
through which end-users access and manipulate the database’s data.
24
S.BHARGAVI Lecturer in Computer science
End users are the people who use the application programs to run the
organization’s daily operations.
For example, salesclerks, supervisors, managers, and directors are all
classified as end users.
High-level end users employ the information obtained from the database to
make tactical and strategic business decisions.
4. Procedures
Procedures are the instructions and rules that govern the design and use of
the database system.
Procedures are another important component of the DBMS system.
Procedures play an important role in a company because they enforce the
standards by which business is conducted within the organization and with
customers.
Procedures are also used to ensure that there is an organized way to
monitor and audit both the data that enter the database and the information
that is generated through the use of those data.
5. Data
The word data covers the collection of facts stored in the database.
Because data are the raw material from which information is generated, the
determination of what data are to be entered into the database and how
those data are to be organized is a vital part of the database designer‟s job.
25
S.BHARGAVI Lecturer in Computer science
In the above diagram:
It shows the DBMS architecture.
Mapping is used to transform the request and response between various
database
levels of architecture.
Mapping is not good for small DBMS because it takes more time.
In External / Conceptual mapping, it is necessary to transform the request from
external level to conceptual schema.
In Conceptual / Internal mapping, DBMS transform the request from the
conceptual to internal level.
1. Internal Level
The internal level has an internal schema which describes the physical storage
structure of the database.
The internal schema is also known as a physical schema.
It uses the physical data model. It is used to define that how the data will be
stored in a block.
The physical level is used to describe complex low-level data structures in detail.
2. Conceptual Level
The conceptual schema describes the design of a database at the conceptual
level.
Conceptual level is also known as logical level.
The conceptual schema describes the structure of the whole database.
The conceptual level describes what data are to be stored in the database and
also describes what relationship exists among those data.
In the conceptual level, internal details such as an implementation of the data
structure are hidden.
Programmers and database administrators work at this level.
3. External Level
At the external level, a database contains several schemas that sometimes called
as subschema.
The subschema is used to describe the different view of the
database.
An external schema is also known as view schema.
Each view schema describes the database part that a particular user group is
interested and hides the remaining database from that user group.
The view schema describes the end user interaction with database systems
26
S.BHARGAVI Lecturer in Computer science
Frequently, organizations that adopt the database approach need to hire or
train individuals to design and implement databases.
This personnel increase seems to be expensive, but an organization should
not minimize the need for these specialized skills.
Installation and Management Cost and Complexity:
A multi-user database management system is large and complex software
that has a high initial cost.
It requires trained personnel to install and operate, and also has annual
maintenance costs.
Installing such a system may also require upgrades to the hardware and
data communications systems in the organization.
Conversion Costs:
The term “legacy systems” is used to refer to older applications in an
organization that are based on file processing.
The cost of converting these older systems to modern database technology
may seem prohibitive to an organization.
Need for Explicit Backup and Recovery:
A shared database must be accurate and available at all times.
This raises the need to have backup copies of data for restoring a database
when damage occurs.
A modern database management system normally automates recovery
tasks.
Organizational Conflict:
A database requires an agreement on data definitions and ownership as well
as responsibilities for accurate data maintenance.
The conflicts on data definitions, data formats and coding causes updating
of shared data.
Handling these issues requires organizational commitment to the database
approach.
Sharing of data Due to the centralized approach, data Data is distributed in many files,
sharing is easy. and it may be of different
formats, so it isn't easy to share
data.
Data DBMS gives an abstract view of data The file system provides the
Abstraction that hides the details. detail of the data representation
27
S.BHARGAVI Lecturer in Computer science
and storage of data.
Security and DBMS provides a good protection It isn't easy to protect a file
Protection mechanism. under the file system.
Recovery DBMS provides a crash recovery The file system doesn't have a
Mechanism mechanism, i.e., DBMS protects the crash mechanism, i.e., if the
user from system failure. system crashes while entering
some data, then the content of
the file will be lost.
Manipulation DBMS contains a wide variety of The file system can't efficiently
Techniques sophisticated techniques to store and store and retrieve the data.
retrieve the data.
Concurrency DBMS takes care of Concurrent access In the File system, concurrent
Problems of data using some form of locking. access has many problems like
redirecting the file while
deleting some information or
updating some information.
Where to use Database approach used in large File system approach used in
systems which interrelate many files. large systems which interrelate
many files.
Data Due to the centralization of the In this, the files and application
Redundancy database, the problems of data programs are created by
and redundancy and inconsistency are different programmers so that
Inconsistency controlled. there exists a lot of duplication
of data which may lead to
inconsistency.
Structure The database structure is complex to The file system approach has a
design. simple structure.
28
S.BHARGAVI Lecturer in Computer science
Data Models In the database approach, 3 types of In the file system approach,
data models exist: there is no concept of data
models exists.
o Hierarchal data models
Flexibility Changes are often a necessity to the The flexibility of the system is
content of the data stored in any less as compared to the DBMS
system, and these changes are more approach.
easily with a database approach.
Objectives of DBMS
The various objectives of DBMS are as follows…
1. Mass Storage
DBMS can store a lot of data in it.
So for all the big firms, DBMS is really ideal technology to use.
It can store thousands of records in it and one can fetch all that data
whenever it is needed.
2. Removes Duplicity
If you have lots of data then data duplicity will occur for sure at any
instance.
DBMS guarantee it that there will be no data duplicity among all the records.
While storing new records, DBMS makes sure that same data was not
inserted before.
3. Multiple Users Access
No one handles the whole database alone.
There are lots of users who are able to access database.
So this situation may happen that two or more users are accessing
database.
They can change whatever they want, at that time DBMS makes it sure that
they can work concurrently.
4. Data Protection
Information such as bank details, employee’s salary details and sale
purchase details should always be kept secured.
Also all the companies need their data secured from unauthorized use.
DBMS gives a master level security to their data.
No one can alter or modify the information without the privilege of using
that data.
5. Data Backup and recovery
Sometimes database failure occurs so there is no option like one can say
that all the data has been lost.
There should be a backup of database so that on database failure it can be
recovered.
29
S.BHARGAVI Lecturer in Computer science
DBMS has the ability to backup and recover all the data in database.
6. Everyone can work on DBMS
There is no need to be a master of programming language if you want to
work on DBMS.
Any accountant who is having less technical knowledge can work on DBMS.
7. Integrity
Integrity means your data is authentic and consistent.
DBMS has various validity checks that make your data completely accurate
and consistence.
8. Platform Independent
One can run dbms at any platform.
No particular platform is required to work on database management system.
30