Book Database Management System
Book Database Management System
P. SREELATHA
MCA., (Ph.D)
Dr. M. SREEDEVI
Ph.D
DATABASE MANAGEMENT SYSTEM 2
© P. SREELATHA
Dr. M. SREEDEVI
Publisher :
Harshwardhan Publication Pvt.Ltd.
Limbaganesh, Dist. Beed (Maharashtra)
Pin-431126, vidyawarta@gmail.com
Printed by :
Harshwardhan Publication Pvt.Ltd.
Limbaganesh, Dist. Beed, Pin-431126
www.vidyawarta.com
ISBN 978-93-90284-70-2
Price : 200/ -
Content
UNIT – I - 04
Overview of Database Management System
UNIT – II - 13
File Base Vs Database Systems
UNIT – III - 39
Entity-Relationship (ER) Model
Chapter – II - 58
Extended Entity Relationship Modeling (EE-R Model)
Chapter – III - 68
Relational Data Modeling
Chapter – IV - 77
Normalization of Database Tables
UNIT – IV - 92
Structured Query Language.
Chapter – I
Introduction to Structure Query Language (SQL)
UNIT – V - 116
Procedural Language / SQL (PL/SQL)
Chapter – 1
Introduction of PL/SQL
DATABASE MANAGEMENT SYSTEM 4
UNIT – I
Chapter – 1
Introduction of Database System
==============***********===============
(Q). Define what is Data, Information and Information
Processing?
Basic Concepts and Definition: -
DATA
INFORMATION
Data:-
Def.1: - Data referred to “Collection of the Facts &
Figures”.
Def. 2: - Data referred to “known facts” that could be
recorded and stored on computer media.
Ex: In a student table, the data would include facts
such as student name, age, address, and marks.
Def. 3: - Data are “Raw Facts”. The word raw indicates
that the facts have not yet been processed to reveal their
meaning.
Def. 4: - “Data consist of facts, text, graphics, images,
sound and video segments that have meaning in
the users environment”.
Information: -
The terms data and information are closely related,
and in fact are often used Interchangeably.
Def 1: - “Information is a process of meaningful of
Data is known as Information”.
DATABASE MANAGEMENT SYSTEM 5
Example: - India won the match against Australia by
100 runs.
Def 2: - “Data that have been processed in such a
way as to increase the knowledge of the person who uses the
data”. The Information also consists as collection of images,
graphics, etc.
Information Life Cycle: -
UNIT – II
==============***********===============
Basic File Terminology: -
Data:
Data are “Raw facts”. The word raw indicates that the
facts have not yet been processed to reveal their meaning.
Databases today are used to store objects such as
documents, photographic images, sound, and even video
segments. So the following is broadened definition
Ex: - Such as a telephone number, a birth date, a
customer name, and a year-to-date (YTD) sales value.
Field:
A character or group of characters (alphabetic or
numeric) that has specific meaning. A field is used to define
and store data.
Record:
A logically connected set of one or more fields that
describes a person, place, or thing.
File:
A collection of related records. For example, a file
might contain data about vendors of ROBCOR
Company, or a file might contain the records for the
students currently enrolled at S.V. University.
Each file in the system used its own application
programs to store, retrieve, and modify data. And each file
was owned by the individual or the department that
commissioned its creation.
DATABASE MANAGEMENT SYSTEM 14
(Q) Defied Drawbacks of File-Based System? (or) Explain
Demerits Traditional Database System? (or) Explain the File
Processing System (FPS) (or)
Discuss Problems / Disadvantages / Demerits of File
Processing System (FPS)?
Early day s commercial data processing system
involves considerable amount of work compression of File
Processing Systems (FPS). In the conventional file handling
system the data is stored in the form of records and files.
Each file is a collection of records and records is a group of
data fields which are logically related.
Demerits / Disadvantages of File Processing Systems (FPS):
- There are listed below of demerits of File Processing
Systems (FPS):
1. Data Redundancy.
2. Data Inconsistency.
3. Difficult in Data Accessing.
4. Limited Data Sharing.
5. Lengthy Development Times.
6. Excessive Program Maintain.
7. No Data Security.
1. Data Redundancy (Duplicate of Data): - “Data
Redundancy means Duplicated of Data” (or) “Repeated the
same information in several places called Data Redundancy”.
The Duplicate of data is wasteful additional storage space.
Unfortunately duplicate of the data and files often results is
loss of data integrity (unique). The Data Redundancy leads to
higher stooge and access cost. Moreover, the same
information may be duplicated in several files, this duplication
of data over several files is known as data redundancy.
Example: - The same data item may have different
names in different files (or) the same name may be used for
different data items in different files. The Address and
Telephone number of a particular customer
DATABASE MANAGEMENT SYSTEM 15
may appear in a file that consists of Saving account records
and in a file that consists of Checking account records. This
redundancy leads to higher storage & excess cost also leads
to inconsistency.
2. Data Inconsistency: Data Inconsistency means
different copies of the same data are not matching. That
means different versions of same basic data are existing. This
occurs as the result of update operations that are not updating
the same data stored at different places.
3. Difficult in Data Accessing: - It is not easy to retrieve
information using a conventional file processing system.
Convenient and efficient information retrieval is almost
impossible using conventional file processing system.
4. Limited Data Sharing: - Each application has its own
private files with little opportunity to share data outside their
own applications. A requested report may require data from
several incompatible files in separate systems.
5. Lengthy Development T imes: - With the File
Processing System (FPS), there is little opportunity to leverage
previous development efforts. Each new application requires
the developer to start from design by designing new file
formats and descriptions. The length development times
required are often inconsistency with today s fast business
environment.
6. Excessive Program Maintain: - The preceding factors
create a heavy program maintenance load. Organizations that
rely on traditional file processing system. In fact as much as
80% of the total information system development budget may
be devoted to program maintenances in such organization.
7. No Data Security: - It is one of the major
disadvantages of File Processing Systems (FPS). In FPS we
can t give the security to the data, that means the data can
be accessed several users.
DATABASE MANAGEMENT SYSTEM 16
(Q) Define DBMS Approach?
In order to remove all the limitation of a File-Based
Systems, a new approach was required that must be more
effective. So the concept of database was introduced. This
approach is know as Database Approach / DBMS Approach.
Characteristics of DBMS Approach: -
· It is central repository of shared data. It allows several
users to access the database concurrently.
· A fundamental feature of the database approach is
that the database system does not only contain the data but
also the complete definition and description of these data.
These descriptions are basically details about the extent, the
structure, the type and the format of all data and additionally,
the relationship between the data. This kind of stored data is
called “Metadata” (Data about Data).
· Data should be correct with respect to the real world
entity that they represent.
· Data should be protected from unauthorized access.
· Data in a database exist permanently until it is not
explicitly deleted.
Drawbacks of DBMS Approach: -
· Database Management Systems can be difficult to set-
up and operate.
· Database Management Systems can be more
expensive to purchase and operate.
· Recovery is more complex.
· Initial training required for all programmers and users.
(Q). Explain the Database approaches?
(or)
Discuss Role and Advantages / Merits of Database
Approaches System?
The Database Approach number of advantages
compare to File Processing System. The primary advantage is
listed below:
DATABASE MANAGEMENT SYSTEM 17
1. Program Data Independent.
2. Minimal Data Redundancy.
3. Improved Data Consistency.
4. Improved Data Accessibility and Responsibility.
5. Improved Data Sharing.
6. Increased Productivity of Application Development
/ Reduced Program Maintains.
7. Improved Quality of Data.
8. Enforcement Standards.
9. Improved High Data Security.
1. Program-Data Independence: - The separation of
data descriptions from the application programs that use the
data is called data independence. With the database
approach, data descriptions are stored in a central location
called the repository. This property of database systems allows
an organization s data to change and evolve (within limits)
without changing the application programs that process the
data.
2. Minimal Data Redundancy:- The design goal with the
database approach is that previously separate data files are
integrated into a single, logical structure. Each primary fact
is recorded in only one place in the database.
3. Improved Data Consistency: - By eliminating (or
controlling) data redundancy, we greatly reduce the
opportunities for inconsistency.
Ex: If a customer address is stored only once, we
cannot disagree on the stored values. Also, updating data
values is greatly simplified when each value is stored in one
place only. Finally, we avoid the wasted storage space.
4. Improved Data Accessibility and Responsiveness: -
With a relational database, end users without programming
experience can often retrieve and display data.
Example: - select * from student where
student_id=999;
DATABASE MANAGEMENT SYSTEM 18
5. Improved Data Sharing: - A database is designed as
a shared corporate resource. Authorized internal and external
users are granted permission to use the database, and each
user is provided one or more user views to facilitate this use.
6. Increased Productivity of Application Development
: - A major advantage of the database approach is that it
greatly reduces the cost and time for developing new business
applications. From the above all factors, as a result program
maintenance can be significantly reduced in a modern
database environment.
7. Improved Data Quality: - The database approach
provides a number of tools and processes to improve data
quality.
8. Enforcement Standards: - When the database
approach is implemented with full management support, the
database administration function should be granted single-
point authority and responsibility for establishing and
enforcing data standards. These standards will include naming
conventions, data quality standards, and uniform procedures
for accessing, updating, and protecting data.
9. Improve High Data Security: - By Using Database to
provide the high data security in terms of passwords.
(Q) Explain the Range of Database Approaches?(or)
Explain Types of Databases?
A DBMS can support many different types of
databases.
Database can be classified according to number of
users, the database locations and the expected type and
extent of use.
DATABASE MANAGEMENT SYSTEM 19
Types of Databases
Advantages: -
· A Single-Tier System requires only one stand-alone
computer.
· It also requires only one installation of proprietary
software.
Disadvantages: -
· May be used by only one user at a time.
· A Single-Tier system impractical for an organization
which requires two or more users to not interact with the
organizational data store at the same time.
(II). Two-Tier Architecture: -
· Two-Tier Architecture consists of two systems, a Client
and Server.
DATABASE MANAGEMENT SYSTEM 35
· The database is stored on the Server, and the interface
used to access the database is installed on the Client.
· The Client being the First Tier and the Server being
the Second Tier.
· The Client requests services directly from Server.
Therefore Client communicates directly with the Server without
help of other tools.
Advantages: -
· Easy to implements on both sites.
· Tools are relatively inexpensive.
· The Two-Tier Client and Sever provides much more
attractive Graphical User Interface (GUI) applications that
were possible with earlier technology.
· Two-T ier Architecture maintains a persistent
connection between the Client and Server/ Database.
· Offers a great deal of flexibility and simplicity in
management.
Disadvantages: -
· Since actual data processing of data takes places on
the remote / server side. The data has to be transported over
the networks. This leads to the increased network stress.
(III). Three-Tier Architecture: -
In Three-Tier Architecture, the Client requests are
handled by intermediate servers which coordinate the
execution of the Client request with subordinate Servers. It
adds Middleware (Middle Tier), which provides a way for
clients of DBMS to access data from another DBMS.
DATABASE MANAGEMENT SYSTEM 36
Three-Tier Architecture.
1. First-Tier (The Client Tier): - In this tier Client send
the request for the information. The main responsibility of
this tier is to receive user events and to control the user
interface and presentation of data. As most of the software
is removed from the Client, the Client is called “Thin Client”.
2. Second-Tier (Application Server / Middle Tier): -
The complex application logic is loaded her and available to
the Client Tier on request from Client. This tier can protect
direct access of data.
3. Third-Tier (Database Server Tier): - The Third tier
contains the data that is needed for the application therefore
this tier is responsible for the data storage. This server mostly
operates on a relational database.
Advantages: -
· It improved Scalability and Integrity.
· The Middle Tier can ensure that only valid data is
allowed to be updated in the database.
· It provides high security. The Client does not have
direct access to the database.
· Load balancing is easier with the separation of the
core business logic from the database server.
· The need for less expensive hardware because the
Client is „Thin†.
· The added modularity makes it easier to modify or
replace one tier without affecting the other tier.
DATABASE MANAGEMENT SYSTEM 37
Disadvantage: -
· More complex than Two-Tier Client-Server computing
model.
· The Client does not maintain a persistent database
connection.
· A separate proxy server may be required.
· Network traffic will be increase, if a separate proxy
server is used.
(IV). N-Tier Architecture: -
In Three-Tier Architecture, each Server (Application
Server and Database Server) perform a specialized task or
service. A server can therefore use services from other servers
in order to provide its own service. The Three-Tier Architecture
is potentially an N-Tier Architecture.
DATABASE MANAGEMENT SYSTEM 38
Advantages: -
· Overall performance has been improved.
· The business logic is centralized.
· Enhanced security level is obtained.
· Provides many services to many Clients.
· Enhanced scalability and availability.
Disadvantage: -
· Much more complicated to design than Two-Tier and
Three-Tier models.
· Load balancing is harder.
· More difficult to maintain software.
· The overall cost of the software and hardware is
usually high.
(Q) Define DBMS Vendors and their Products?
Some of the popular DBMS Vendors and their
corresponding products are listed following:
DATABASE MANAGEMENT SYSTEM 39
UNIT – III
Entity-Relationship (ER) Model
==============***********===============
(Q) Explain Data Model Basic Building Blocks?
The basic building blocks of all data models are
Entities, Attributes, Relationships and Constraints.
Entity: - An entity is a person, place, object events, in
the user environment about which the organization to maintain
of data.
Example: -
Place : Rompicherla, Piler, Tirupati, Hyderabad etc.
People : Students, Employees, Workers etc.
Objects : Automobiles, Machine, Building etc.
Events : Sales, Registration, Renewal etc.
Attribute: - An attribute is a property or
characteristics of an Entity Type.
Example: -
STUDENT : Student_Id, Student_Name, Course.
EMPLOYEE : Emp_Id, Emp_Name, Payroll, Skills.
Relationship: - “A relationship type is a meaningful
association between (or among) entity types”.
Constraints: - constraints are a condition or restriction
placed on the data.
(Q) Introduction of Entity Relationship Models (E-R
Models)?
An Entity Relationship Model is a detailed, logical
representation of the data for an organization or for a business area.
The Entity Relationships Models is expressed in teams
of Entities, the relationships among those entities and the
attributes of both the entities and their relationships.
DATABASE MANAGEMENT SYSTEM 40
An Entity Relationship Model is normally expressed
as an entity relations diagrams, which is a graphical
representations of Entity Relationships Models.
Definitions: -
1. Entity: - An entity is a person, place, object events,
in the user environment about which the organization to
maintain of data.
Example: -
Place : Rompicherla, Piler, Chittoor, Hyderabad etc.
People : Students, Employees, Workers etc.
Objects : Automobiles, Machine, Building etc.
Events : Sales, Registration, Renewal etc.
2. Entity Type: - A Collection of entities that shared a
common property or characteristics.
3. Entity Instance: - A single occurrence of the entity
type is called as Entity Instances.
Example: -
Entity Type: EMPLOYEE Attributes:
Emp_Name Varchar (20)
Emp_Number Varchar (10)
DOB Date
Two Instances of EMPLOYEE
(1) Emp_Name: ABCD (2) Emp_Name: WXYZ
Emp_Number : 101010 Emp_Number : 202020
DOB : 19-08-1992 DOB : 20-09-1990
Rules: -
1. If a naming attribute we can use initial capital letter
followed by lower case letters.
2. If an attribute name consists two words we can use
underscore ( _ ) character to connected two words.
3. In naming entity we can use only user case.
4. Attribute: - An attribute is a property or
characteristics of an Entity Type.
DATABASE MANAGEMENT SYSTEM 41
Example: -
STUDENT : Student_Id, Student_Name, Course.
EMPLOYEE : Emp_Id, Emp_Name, Payroll, Skills.
(Q). What are the Components of an E-R Model?
The overall logical structure of a database can be
expressed graphically by an E-R Diagrams. Such a diagram
consists of major components listed below.
· Ellipses : It represents Attributes.
· Rectangles : It represents Entity Sets.
· Lines : It represents links attributes to entity sets of
relations.
· Diamonds : It represents Relationships.
· Double Ellipse : It represents Multivalued attributed.
· Dashed Ellipse : It represents Derived attributes.
· Double Lines : It indicates total participation of an
entity in a relationship set.
(Q). What are the Entity Relationship Modeling Symbols?
DATABASE MANAGEMENT SYSTEM 42
Address
Stud_Id Stud_Name
EMPLOYEE
Composite Identifier: - “An Identifier that is consists
of a composite attribute”.
Example:- Consider as a FLIGHT entity that attributes
are Flight_Id, Flight_Number, Date, Number_of_Passengers.
Here candidate identifier is „Flight_Id and also uniquely
identify the Flight_Number that second identifiers is called
as a Composite Identifiers. Here the primary candidate
identifier (Flight_Id) is must be underline and second identifier
(Flight_Number) no need to indicate an underlines.
Flight_Number Date Number_of_Passenger
Flight_Id
FLIGHT
Example: -
Consider the following example. Here „COUSTOMER
is a entity it having two attributes like Cust_Name,
Cust_Ac_No and „TRANSATION is a another entity it having a
two attributes like Deposit, Withdrawn.
TRANSATION
CUSTOMER Has
Example: -
A PERSON is an Entity it s having two attribute like
Name, Age. Another entity is EMPLOYEE it s having two
attributes like Emp_Id, Emp_Name.
DATABASE MANAGEMENT SYSTEM 48
Example: -
An EMPLOYEE entity is having attributes Emp_Id,
Emp_Name. A COURSE having the attributes is Course_Id,
Course_Title. Another entity as CERTIFICATE having the
attributes like Cert_No, Date_Comp. Now the relations
between 3 entities by using associative entity are as following.
EMPLOYEE : Emp_Id, Emp_Name.
CERTIFICATE : Cert_No, Date_Comp
COURSE : Course_Id, Course_Title.
DATABASE MANAGEMENT SYSTEM 49
In this above example the entity CERTIFICATE is an
associative entity. Because we can use this entity as entity
type of relationship.
Entity and types of symbols used in E – R Model: -
S. No Entity Symbols in E-R Model Description
1
Weak Entity
Strong Entity
2
3 Associative Entity
A1 B1
A2 B2
A3 B3
PERSON
Is_Married_to
A1 B1
A2 B2
A3 B3
DATABASE MANAGEMENT SYSTEM 52
Example (1):- Consider as a E-R Diagram it having a
one entity and many relationship it s their One-to-many.
EMPLOYEE
COMPANY
Has
A1 B1
A2 B2
A3 B3
A1 B1
A2 B2
A3 B3
DATABASE MANAGEMENT SYSTEM 54
Example (1):- Consider as a E-R Diagram it having a
one entity and many relationship it s their One-to-many.
DEPARTMENT
MANAGER
Has
A1 B1
A2 B2
A3 B3
DATABASE MANAGEMENT SYSTEM 55
Example (1):- Consider as a E-R Diagram it having a
many entity and one relationship it s their Many-to-one.
BROWED
BOOKS
Issues
A1 B1
A2 B2
A3 B3
DATABASE MANAGEMENT SYSTEM 56
Example (1):- Consider as a E-R Diagram it having a
many entity and many relationship it s their Many-to-many
PARTS
Supplies WAREHOUSE
VENDOR
Shipping_Mode Unit_Cost
CHAPTER-II
==============***********===============
Introduction: -
In order to design the complete structure of any organization,
ER-Modeling symbols are not sufficient. So new features are added
to ER-Model to provide more accurate structure to the ER-Model.
And E-R Model renamed as an “Enhanced / Extended Entity
Relationship Modeling (EE-R Model)”.
There are new features is like an
1. Supertype.
2. Subtype.
3. Generalization.
4. Specialization.
5. Attribute Inheritances.
6. Aggregation.
(Q) How to Representing Supertype / Subtype? Give one
example?
Definition of Supertype: - “A generic entity type that
has a relationship with one or more subtype”.
Definition of Subtype: - “A Sub-grouping of the
entities in an entity type that is meaningful to the organization
and that share common attributes or relationships distinct
from other sub-groupings”.
DATABASE MANAGEMENT SYSTEM 59
Basic Concepts and Notation of Supertype / Subtype: -
Note: -
1. The Supertype is connected with a line to a Circle
in which in term is connected by a line to each Subtypes that
have been define.
2. The (U – Shape) is indicated connecting a Subtype.
3. Here all attributes are shared by all entity are
associated with Supertype.
4. Attributes are unique to a particular subtype,
associated with subtype.
Example: - The following example shows a
representation of the EMPLOYEE Supertype with its three
subtypes using EER-Notations. Consider the following entities
set having the attributes.
Supertype: EMPLOYEE : Emp_No, Emp_Name,
Address.
Subtype:HOURLY_EMPLOYEE : Emp_No, Emp_Name,
Address, Hourly_Rate.
DATABASE MANAGEMENT SYSTEM 60
SALARY_EMPLOYEE : Emp_No, Emp_Name, Address,
Annual_Salary.
CONTRACT_EMPLOYEE : Emp_No, Emp_Name,
Address, Cont_Number, Billing_Rate.
In that above all of the EMPLOYEE types several
attributes in common namely Emp_No, Emp_Name, Address.
In addition each type has one are more attribute distinct from
the attributes of the types.
EMPLOYEE Supertype
PILOT Subtype
a1 a2 a3 a4
IS-A
PERSON
PERSON
Description
Supplier
Part_No Routing_Numbers
Qty_on_Hands
PART Location
enquire
Visitor
CHAPTER-III
==============***********===============
RELATIONAL DATA MODEL: -
Dr. E. F. Codd First introduces the relational data model
in 1970.
“The relational data model represents data in the form of
tables.”
The relational model is based on mathematical theory
and therefore has a solid theoretical foundation.
The relational data model consists of the following
three components
1. Data Structure: Data are organized in the form of
tables with rows and columns.
2. Data manipulation: Powerful operations (using the
SQL language) are used to manipulate data stores in the
relations.
3. Data Integrity: Facilities are included to specify
business rules that maintain the integrity of data when they
are manipulated.
RDBMS Terminology: -
Fo rmal Relation al term Informal eq uivalent
Relation Table
Tuple Row, Reco rd
Attribute Colum n, Field
Cardinality No. of Rows
Degree No. of c olum ns
Domain Set o f legal values
Primary key Unique identification
DATABASE MANAGEMENT SYSTEM 69
(Q) What is a Relation? Explain the different representation
methods of relations with example?
Relation: - “A relation is a table in DMBS a relation
consider as set of rows and columns”. Every relation must
consist named columns and unnamed rows.
Properties of Relationship: -
1. Every ration contains named columns and unnamed rows.
2. Table attributes must be unique names.
3. Table names must be unique.
4. The values in the cells should be „atomic .
Representation of a relation: -
Normally a relation may be represented in two possible
methods.
1. Textual Representation.
2. Graphical Representation.
1. Textual Representation: - In this representation
total table structure like name of the table and its attributes
etc., are expressed in text format. In textual representation
the name of the table followed by attributes with in
parenthesis.
Syntax: - Table name ( Attribute name 1, Attribute
name 2, Attribute name n)
Example: - EMPLOYEE ( Emp_Id, Emp_name, Salary,
Dept_No).
2. Graphical Representation: - In this representation
name of the table takes place on the top position and
attributes placed with in connected rectangles.
DATABASE MANAGEMENT SYSTEM 70
CHAPTER-IV
==============***********===============
(Q) what is Normalization? Explain in details with an
suitable examples?
Definition: - “Normalization is a process for evaluating
and correcting table structures, to minimize the data
redundancies by reducing the data anomalies”.
(OR)
“Normalization is the process of decomposing
relations with anomalies to produce smaller, well-structured
relations”.
Normalization is primary a tool to validate and improve
a logical design, so that is satisfies certain constraints that
“avoid unnecessary duplication of data”. Normalization works
through a series of steps called Normal Forms. We have
different types of Normal Forms there are.
Types of Normalizations: - In relational model all
Normal Forms are broadly classified into two types.
1. Basic Normal Forms 1 NF, 2 NF & 3 NF.
2. Advanced Normal Form BCNF, 4 NF & 5NF.
Steps in Normalizations: -
· First Normal Form (1 NF) “Any Multi-valued
attributes have been removed”, so there is a single at the
intersection of each row and column of the table.
· Second Normal Form (2 NF) “Any Partial Functional
Dependencies have been removed”.
· Third Normal Form (3 NF) “Any Transitive
Dependencies have been removed”.
DATABASE MANAGEMENT SYSTEM 78
· Boyce Codd Normal Form (BCNF)“Any remaining
anomalies that result from functional dependencies have been
removed”
· Fourth Normal Form (4 NF) “Any Multi-valued
Dependencies have been removed”.
· Fifth Normal Form (5 NF) “Any remaining
anomalies have been removed”.
Needs of Normalization: -
The tables are the basic building block in the database
design process. Every table has its own structure. In some
cases even a good database design contains a poor table
structure to identify these tables and convert them as good
tables. We need normalization.
The Poor table structure contains anomalies. The main
need of Normalization is to reduce the anomalies. We have 3
types of data anomalies, there are
1. Insert Anomalies.
2. Update Anomalies.
3. Delete Anomalies.
1. Insert Anomalies: - If you insert any row in a
relation, the remaining rows are affected then we can say
that the relation has Insert Anomalies.
2. Update Anomalies: - If you update any value in a
relation, then remaining values in the relation are
unnecessarily affected. Then we can say that there is an Update
Anomalies.
3. Delete Anomalies: - If you delete any row in a
relation the remaining rows in a relation are unnecessarily
deleted then we can say that there is a Delete Anomalies.
Normalization Process: - The main objective of
Normalization process is to break the tables and create new
tables. This process contains the following characteristics.
Each table represents the single subject.
DATABASE MANAGEMENT SYSTEM 79
No data item will be unnecessarily stored in more than
one table.
All Non-Keys attributes are dependents of the Primary
Key.
Each table doesn t contain Insertion, Update &
Deletion Anomalies.
Multi-Value Attributes: - A Single Attribute contain
the more than one values in the relational table. is known as
Multi-Value Attribute or Repeating Groups.
Functional Dependencies and Keys: -
Definition: - “A Functional Dependency is a constraints
between two attributes or two sets of attributes” The
functional Dependency of “B on A” is represented by an arrow,
as follows A à B. Here „A is determination and „B is the
dependency.
Example: - 1. Consider the relation COURSE (Emp_Id,
Course_Title, Date_Completed). We represent the functional
dependency in this relation as follows.
Emp_Id, Course_Title à Date_Completed.
Determination: - “The attribute on the Left-hand side
of the arrow in a functional dependency is called as a
Determination”.
Candidate Key: - “A Candidate key is an attributes or
combination of attributes that uniquely identify a row in a
relation” The Candidate key must satisfy the following
properties.
· Unique Identification: - For each row the value of the
key must uniquely identify that row.
· Non-Redundancy: - No attributes in the key can be
deleted without destroying the properties of unique
identification.
Representation of Functional Dependencies: - We
represent the functional dependencies for a relation using
the notations shown in the following.
DATABASE MANAGEMENT SYSTEM 80
Example 1: - Show the representation for EMPLOYEE 1
Example: -
Consider the following example table relation of
EMPLOYEE that has attributes like Name, Project and Hobbies.
A row in the EMPLOYEE table that an employee works for a
Projects and has a Hobbies. But an employee can work in
more than one project and more than one Hobby. The employee
projects and hobbies are independent of one another to keep
the relation consist we must have separated tables of
represented every combination of employee project and
employee hobbies. This contains specific multivalue
dependences of on EMPLOYEE table.
DATABASE MANAGEMENT SYSTEM 90
EMPLOYEE
Nam e P ro je ct H o b b i es
A l e xi s M ic r os of t R ea di n g
A l e xi s O r a c le M us ic
A l e xi s M ic r os of t M us ic
A l e xi s O r a c le R ea di n g
M a t h ew s I n te l M o v ie s
M a t h ew s S y b a se R a i d i ng
M a t h ew s I n te l R a i d i ng
M a t h ew s S y b a se M o v ie s
In that above table the values has been multiple-
functional dependencies. Now to remove multi-value
dependencies in EMPLOYEE table. By using de-composing of
a table. The 4th Normal form as following.
PROJECT
Project Emp_Name
Microsoft Alexis
Oracle Alexis
Intel Mathews
Sybase Mathews
HOBBY
Hobbies Emp_Name
Reading Alexis
Music Alexis
Movies Mathews
Raiding Mathews
(Q) Explain the 5th Normal Form? With an example?
5th Normal Form: - A relation is said to be in 5th
Normal Form if it doesn t contains multiple relationships, such
type of relation are rarely available in DBMS. If any relation
contains multiple relations, they should be resolved into simple
relations by using normalization.
Consider the following relations LAB_PRODUCT_
COMPANY.
DATABASE MANAGEMENT SYSTEM 91
LAB_PRODUCT_COMPANY
Lpc_Id Lab_Id Prod_Id Company_Id
UNIT – IV
Chapter – I
Introduction to Structure Query Language
(SQL)
==============***********===============
Structured Query Language (SQL) is the standard
command sets, use to communicate with the relational
database management systems (RDBMS).
All tasks related to RDBMS creating tables, queries,
modification of tables, deleting of tables from the database.
SQL is to granting the access to user and database.
History of SQL: - SQL was first introducing by “Dr. E. F.
Codd”. He works on Relational Model for large sharing
databank. Since it s introducing many researches at the
“SanJose” Research Laborites.
The mid of 1970 s development many computer
programming languages based on this relation model one of
this called as a “Structured English Query Language”
(SEQUEL). These languages are used for an IBM prototype
machines called as a “Structured English Query Languages
Extensional Relational Model” (SEQUEL-XRM).
In 1976 s IBM s re-launched for this second prototype and
called as a Relational-Systems (R-Systems). One research organization
called relationship software from California commercially available
relational database was ORACLE. Today s ORACLE manufactures a
wide range of SQL products along with ORACLE relational database
management systems software.
DATABASE MANAGEMENT SYSTEM 93
Types of SQL: - SQL is broadly classified into two types.
1. Interactive SQL.
2. Embedded SQL.
1. Interactive SQL: - “Interactive SQL is used for
directly access the data from the database”. Where the output
of operation is used for human consumptions. Once a
command is specified is “executed and output is immediately
view by the users”.
2. Embedded SQL: - “In the case of Embedded SQL
commands are SQL Commands that are written in some
another languages”. Such as COBAL, ALP (Assembly Level
Programming Language). This makes the programmer very fast
and powerful manner.
Advantages of SQL: -
· SQL is a high level language that provides a greater
degree of „abstraction .
· SQL deals with number of database management
system at a time.
· SQL is an English like computer language which makes
interaction between user and database very simply.
· SQL language which being simple and easy to learn
can handle complex situation.
· SQL operations are performed at a set level. One select
statement can retrieve multiple rows.
(Q) What SQL can Do?
· SQL can Retrieve data fro a Database.
· SQL can Execute Queries against a Database.
· SQL can Insert Records in a Database.
· SQL can Update Records in a Database.
· SQL can Delete Records in a Database.
· SQL can Creates New Tables in a Database.
· SQL can Creates Views in a Database.
(Q) Define SQL * PLUS?
SQL * PLUS is a software product from Oracle
DATABASE MANAGEMENT SYSTEM 94
Corporation that allows users to interactively use the SQL
commands, produce formatted reports and support written
command-procedures to access Oracle Database. Though SQL
* PLUS, a user can Do:
· Enter, Edit, Store, Retrieve and Run SQL Commands.
· Format, Perform calculations, Print Query results in
the form of Reports.
· Access and Copy data between SQL Database.
· Send messages to and accepts responses fro an End-
Users.
(Q) Explain the difference between SQL and SQL * Plus?
SQL SQL * PLUS
SQL is a special-purpose language used to define,access and SQL * PLUS is a command line tool that allows user to type
manipulate data in RDBMS like Oracle SQL commands to be executed directly against an Oracle
Database.
SQL provides set of commands used to SQL* PLUS is the environment where you canactually
communicate with the Database to perform type your commands to perform specific
specific tasks. tasks.
SQL commands can be used to create tablesobjects SQL * PLUS commands can be used to describe the structure
like Create, Alter, drop etc. of Database objects. For example: DESCRIBE/DESCRIPTION is
DESC command.
SQL commands cannot be abbreviated. In SQL * PLUS commands can be abbreviated.Like the
commands EDIT can be ED.
Every SQL commands must be ended withsemicolon In SQL * PLUS semicolon (;) is optional.
(;)
emp;COUNT (*)
14
4 rows deleted.
SQL> COMMIT;
Commit complete.
emp;COUNT (*)
10
DATABASE MANAGEMENT SYSTEM 101
(2) TRUNCATE: - TRUNCATE removes all rows from a
table. The operation cannot be rolled back and no triggers
will be fired. As such, TRUCATE is faster and doesn’t use as
much undo space as a DELETE.
SQL> TRUNCATE TABLE emp;
Table truncated.
SQL> SELECT COUNT(*) FROM emp;
COUNT(*)
0
(3) DROP: - The DROP command removes a table from
the database. All the tables’ rows, indexes and privileges will
also be removed. No DML triggers will be fired. The operation
cannot be rolled back.
SQL> DROP TABLE emp;
Table dropped.
SQL> SELECT * FROM emp; SELECT * FROM emp
* ERROR at line 1:
ORA-00942: table or view does not exist.
DROP and TRUNCATE are DDL commands, whereas
DELETE is a DML command. Therefore DELETE operations can
be rolled back (undone), while DROP and TRUNCATE
operations cannot be rolled back.
(Q) Explain Query In SQL?
A “Query is a Question” in the Structured Query
Language. As its name denote SQL is best at writing Queries.
Anything that is apart of RDBMS table can be retrieved at the
users request using SQL. A SQL Query has five basic parts
that are
1. Select
2. From
3. Where
4. Group By
5. Order By
DATABASE MANAGEMENT SYSTEM 102
1. Select: - This command comprise of the list of
columns that have to be displayed in the Query result. If you
want all the columns of a table to be displayed, instead of
writing down all the column names you could simply use an
astric (*).
2. From: - This part identified the source tables of all the
columns. These could be a single table or more than one table.
3. Where: - This is an “Optional Part of a Query” this
part specified the limits that the result. If a Query does not
have a Where Clause all the rows are selected comparisons
can also is specified in this clause.
Ex:-If the librarian wants to see the list of all members
who have borrowed books on the date 15-08-2009 Select book
code from member where issues date = „15-08-2009 ;
4. Group By: - This is another optional part of a Query.
If is used only when the results of the Query have to be
Grouped based on criteria. Expressions can be specified as
criteria for this clause.
Ex: - If the average salary of employees in a
department is to be from the following Query can be used.
Select dept_no, avg(pay) from employee group by dept_no;
5. Order By:- This is an optional clause that controls the
order in which the rows to be display by the Queries are ordered.
Ex:- If the Librarian wants the results of the Query to
be ordered by book code, this is the following query Select
book_code from member where issues date = „15-08-2009
order by book_code;
(Q) Difference between Where and Having Clause in SQL?
WHERE CLAUSE HAVING CLAUSE
Where Clause of the SELECT statement ismainly Having Clause for SELECT statement
used for conditional retrieved of records ismainly used for
from a database table. conditional retrieval of
records from grouped results.
Where Clauses can ne used without the Group Having Clause cannot be used without the
By Clause. Group By Clause.
Where Clause cannot contain Group Function. Having Clause can contain Group Functions.
Where Clause selects records before grouping. Having Clause selects records after grouping.
DATABASE MANAGEMENT SYSTEM 103
(Q) What are the Integrity constraints?
Integrity constraints are used to ensure accuracy and
consistency of data in a relational database. Data integrity is
handled in a relational database through the concept of
referential integrity. There are many types of integrity
constraints that play a role in referential integrity.
Types of Integrity Constraints: -
· Entity Integrity.
· Referential Integrity.
· Domain Integrity.
· User Define Integrity.
Entity integrity: - The entity integrity constraint states
that no primary key value can be null. This is because the
primary key value is used to identify individual Tuples in a
relation. Having null value for the primary key implies that we
cannot identify some tuples. This also specifies that there may
not be any duplicate entries in primary key column key row.
Referential Integrity: - The referential integrity
constraint is specified between two relations and is used to
maintain the consistency among tuples in the two relations.
Informally, the referential integrity constraint states that a
tuples in one relation that refers to another relation must refer
to an existing tuple in that relation. It is a rule that maintains
consistency among the rows of the two relations
Domain Integrity: - The domain integrity states that
every element from a relation should respect the type and
restrictions of its corresponding attribute. A type can have a
variable length which needs to be respected. Restrictions could
be the range of values that the element can have, the default
value if none is provided, and if the element can be NULL.
User Defined Integrity: - A business rule is a statement
that defines or constrains some aspect of the business. It is
intended to assert business structure or to control or influence
the behavior of the business. E.g.: Age>=18 && Age<=60.
DATABASE MANAGEMENT SYSTEM 104
(Q) Grouping Data from Tables in SQL?
1. Group by Clause
2. Having Clause
1. Group by Clause: - The Group by Clause is another
section of the select statement. This option clause tells Oracle
to group rows based on distinct values that exist for specified
columns. Therefore it crated a database containing several
sets of records group together based on a condition. In Group
by option we can use aggregate functions also. The syntax of
Group by Clause is following.
Syntax: - select <column list> from <table name>
group by <column name>;
Example: - Retrieve the product number and the total
quantity order for each product from the sales_order details
tables.
Table Name: - Sales_Order
Order_no product_no Quality_order Quality_Dis
30402 p001 10 10
30402 p004 03 03
30402 p006 07 07
40300 p002 04 04
40300 p005 10 10
30240 p003 02 02
30430 p001 06 06
30670 p006 04 04
30670 p004 01 01
30700 p006 08 08
Records Records
Only in Only in
Query Query
one
Two
Query: - List all Employee id, names in the Table1 and Table2
DATABASE MANAGEMENT SYSTEM 114
SQL> select id,name from far1 union all select id, name from
far2;
Output: -
ID NAME
100 Naresh
101 Kumar
102 Swamy
103 Fareed
104 Lakshmi
106 Kalavathi
105 James
103 Fareed
107 Gayathri
101 Kumar
10 rows selected.
Difference between Union and Union All: -
UNION UNION ALL
It displays distinct rows from both tables.It It can display distinct rows and duplicate
cannot display duplicate records. records also.
Using the keyword UNION Using the keyword UNION ALL
We cannot find out the total number of We can find out the table numbers of
records in a table records in a table.
3. INTERSECT Operator: - “The Intersect Operator
returns the rows that are common between the Tables”.
Common
records in
both
queries
Query: - List the common Employee id, names from Table1 &
Table2
Syntax: - select <column names> from <table name> where [ condition]
INTERSECT
Select<column names> from <table name> where [condition] ;
A–B B–A
Query: - List the Employee id, names present in Table1
but not in Table2.
Syntax: -
select <column names> from <table name> where [ condition]
MINUS
Select<column names> from <table name> where [condition]
SQL> select id,name from far1 minus select id, name
from far2;
Output: -
ID NAME
100 Naresh
102 Swaamy
104 Lakshmi
Query: - List the Employee id, names present in Table2
but not in Table1.
SQL> select id, name from far2 minus select id, name
from far1;
DATABASE MANAGEMENT SYSTEM 116
UNIT – V
Chapter – 1
Introduction of PL/SQL
==============***********===============
Introduction: -
· SQL does not support programming. It is used to write
single line statement called Quarries.
· To support programming constructs, additional
features are added to SQL and name it as PL/SQL.
· PL/SQL is very useful to develop programming.
· PL/SQL supports almost all programming constructs
like variables, conditional statements, looping etc.,
Architecture of PL/SQL: -
PL/SQL Engine
PL/SQL Block Structure: -
The Programming area in PL/SQL is called block. This
block mainly contains Three parts. They are:
1. Declarative Part.
2. Executable Part.
3. Exception Handling part.
DATABASE MANAGEMENT SYSTEM 117
Structure:-
SQL> Declare
……………
…………… Variable Declaration
……………
Begin
Statement 1
Statement 2 Executable Part
……………
End;
Exception Error Handling Part
The above syntax shows that every PL/SQL block
declarative part should be indicated with a key word called
“Declare”. Executable part must be enclosed with in begin
and end key words. Exception Handling part can be indicated
with a key word called it “Exception”.
Input & Output Statement in PL/SQL: -
1. Input Statement: - The Input statement in PL/SQL
is “ & “ Operator. The „& Operator it is to give the Input
values to the Variables.
Ex:- a : = & a;
x : = & x; ………
2. Output Statement: -The Output Statement in PL/
SQL is “dbms_output.put_line(„Message /Variables);”
Ex: - SQL> dbms_output.put_line( „ Welcome to PL/
SQL );
(Q) Explain various Advantages and Disadvantages of PL/
SQL? Advantages of PL/SQL: -
Block Structures: PL SQL consists of blocks of code,
which can be nested within each other. Each block forms a
unit of a task or a logical module. PL/SQL Blocks can be stored
in the database and reused.
Procedural Language Capability: PL/SQL consists of
procedural language constructs such as conditional
DATABASE MANAGEMENT SYSTEM 118
statements (if else statements) and loops like (FOR loops).
Better Performance: PL SQL engine processes
multiple SQL statements simultaneously as a single block,
thereby reducing network traffic.
Error Handling: PL/SQL handles errors or exceptions
effectively during the execution of a PL/SQL program. Once
an exception is caught, specific actions can be taken
depending upon the type of the exception or it can be displayed
to the user with a message.
Modularity: - Modularity means divide an application
or a process into manageable, well defined modules. PL/SQL
allows process to be divided into different modules such as
procedures and functions called „subprograms .
Portability: - Applications written in PL/SQL are
portable to any platform on which Oracle runs. One you write
a program in PL/SQL, it can be used in any environment
without any change at all. (WORM).
Disadvantages of PL/SQL: -
Proprietary of Oracle: - PL/SQL is proprietary to
Oracle which means if you were to change database vendors
then you would have to re-write all your Oracle PL/SQL
programs. Also if you use a mixture of databases or develop
applications to run on different databases, you will either have
to support lots of source code or write your applications in a
database-neutral language like: Java or Visual Basic.
Poor I/O Feature: - The other limitation of Oracle PL/
SQL is that there is very little support for I/O either to Read/
Write files to user interface.
Insufficient Memory: - More Memory may be required
on the Oracle database server when using Oracle PL/SQL
packages as whole packages is loaded into memory as soon
as any object in package is accessed.
DATABASE MANAGEMENT SYSTEM 119
(Q) Explain Fundamental of PL/SQL (or) PL/SQL Language
Elements?
Like every other programming language, PL/SQL has a
set of elements like Character Set, Reserved Words, Identifiers,
and Literals etc. these elements of PL/SQL are used to
represented real world entity or objects and operations.
· Character Set.
· Reserved Words.
· Delimiters.
· Literals.
· Lexical Units.
Character Set: - PL/SQL programs are written as lines
of text using a specific set of characters. The PL/SQL
characters set includes: Letters (a..z and A..Z), Numbers (0..9)
Tabs, Space, Special Symbols (+,-, <>, !, #, [], {} ). PL/SQL is
not a case sensitive.
Reserved Words: - Reserved words have special
syntactic meaning of PL/SQL and so it can not be redefined.
Reserved words are generally written in upper case to promote
readability, but it can be written in lower or mixed case.
Delimiters: - Delimiters are simple or compounds
symbols that have special meaning to PL/SQL. Delimiters are
like: +, -, <>, !=, ||, /*, :=, etc.
Literals: - A literal is an explicit numeric, character,
string or Boolean values that are not represented by
identifiers.
Lexical Units: - A line of PL/SQL text contains groups
of characters known as lexical unit. To improve readability,
you can separate lexical units by spaces. In fact, you must
separate adjacent identifiers by a space of punctuations.
(Q) Explain how to declare variables and constants in PL/
SQL?
PL/SQL Variables: - These are placeholders that store
the values that can change through the PL/SQL Block.
DATABASE MANAGEMENT SYSTEM 120
The General Syntax to declare a variable is: Variable_Name
datatype [NOT NULL := value ];
· Variable_Name is the name of the variable.
· datatype is a valid PL/SQL datatype.
· NOT NULL is an optional specification on the variable.
· value or DEFAULT values also an optional specification,
where you can initialize a variable.
· Each variable declaration is a separate statement and
must be terminated by a semicolon.
For example: - If you want to store the current salary
of an employee, you can use a variable.
DECLARE
salary number (6);
· “salary” is a variable of datatype number and of length 6.
When a variable is specified as NOT NULL, you must
initialize the variable when it is declared.
For example: - The below example declares two
variables, one of which is a not null.
DECLARE
salary number(4);
dept varchar2(10) NOT NULL := “HR Dept”;
The value of a variable can change in the execution or
exception section of the PL/SQL Block. We can assign values
to variables in the two ways given below.
1) We can directly assign values to variables.
The General Syntax is: - variable_name:= value;
2) We can assign values to variables directly from the
database columns by using a SELECT.. INTO statement.
The General Syntax is: SELECT column_name INTO
variable_name FROM table_name [WHERE condition];
Example: - The below program will get the salary of
an employee with id ‘1116’ and display it on the screen.
DECLARE
var_salary number(6); var_emp_id number(6) = 1116;
DATABASE MANAGEMENT SYSTEM 121
BEGIN
SELECT salary INTO var_salary FROM employee
WHERE emp_id = var_emp_id; dbms_output.
put_line(var_salary);
dbms_output.put_line(‘The employee ‘|| var_emp_id
|| ‘ has salary ‘ || var_salary); END;/
NOTE: - The backward slash ‘/’ in the above program
indicates to execute the above PL/SQL Block.
In PL/SQL block, variables are declared in the DECLARE
section.
Scope of Variables: -
PL/SQL allows the nesting of Blocks within Blocks i.e.,
the Execution section of an outer block can contain inner
blocks. Therefore, a variable which is accessible to an outer
Block is also accessible to all nested inner Blocks. The
variables declared in the inner blocks are not accessible to
outer blocks. Based on their declaration we can classify
variables into two types.
Local Variables - These are declared in an inner block
and cannot be referenced by outside Blocks.
Global Variables - These are declared in an outer block
and can be referenced by its itself and by its inner blocks.
For Example: - In the below example we are creating
two variables in the outer block and assigning their product
to the third variable created in the inner block. The variable
‘var_mult’ is declared in the inner block, so cannot be
accessed in the outer block i.e. it cannot be accessed after
line 11. The variables ‘var_num1’ and ‘var_num2’ can be
accessed anywhere in the block.
DATABASE MANAGEMENT SYSTEM 122
Database
Code
Perform