SlideShare uma empresa Scribd logo
1 de 96
Database Management System (DBMS) paper-5 (Syllabus)
Unit-1
Over view of Database management system: Introduction, file-Based system, Draw Backs of
file-based system, Data and information, Database, Database management system,
objectives of DBMS, Revolution of Database management system, classifications DBMS,
DBMS approach, advantages of DBMS, ANSI /spark, data model, Data models, components
and interfaces of Database management system, Database architecture, situations were
where DBMS is not necessary, DBMS venders and their products.
Unit-2
Entity Relationship Mode: Introduction, the building blocks of an unity relationship diagram,
classification of entity sets, attribute classification, relationship degree, relationship
classification, reducing ER diagram to tables, enhanced entity relationship model,
generalization and specializations, Isa relationship and attribute Inheritance, multiple
Inheritance, constraints on specialization and generalization, Aggregation and composition,
entity clusters, connection types, advantage of ER modeling.
Unit-3
Relational Model:
Introduction, CODD rules, Relational data model, concept of key, Relational Integrity,
Relational algebra/relational algebra operations, Advantages of Relational algebra,
limitations of relational algebra, relational calculus, Tuple relational calculus, domain
relational calculus, QBE.
Unit-4
Structure 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, table truncation, imposition of constrains, joint
operation, set operation, view, sub query, embedded SQL.
Unit-5
PL/SQL:-
Introduction, short coming in SQL, structure of PL/SQL,PL/SQL language elements, data
types, operator precedence, control structure, steps to create a PL/SQL program, iterative
control, cursors, steps to create cursor, procedure, function, packages, exception handling,
Database triggers, types of triggers.
Database Management System Unit - 1
Prepared By Page 1
Mr. D. Sulthan Basha Lecturer in Computer Science
Unit-1
1.1 Introduction to Database Management System
Data Processing:-
The activity of processing data using a computer is called data processing (or)
electronic Data processing (EDP). The ultimate goal of data processing is to
transform data into information. It saves time, money and man power.
Data Processing System:-
Data is raw material used as input and information is processed data obtained
as output of data processing.
Being a data processing system computer has importance in providing in-depth
knowledge of whatever is involved in processing the data. But before looking into
that, we require to define some of the basic terms associated with it.
Input:-
Input refers to the data and instructions given to the computers.
Data is a raw set of facts and figures associated with an individual, an entity, or an
event. It is basically a collection of unorganized facts (or) concepts that does not convey any
meaning. Data can be represented in various forms i.e. in figures, characters, symbols,
pictures, audio, video etc.
Data
Capture Data
Manipulate Data
Output Results
Information
Data
Symbols
Words
Images
Videos
Audio
Numbers
Database Management System Unit - 1
Prepared By Page 2
Mr. D. Sulthan Basha Lecturer in Computer Science
Instruction:-
Instruction specifies how the data is to be manipulated. It is basically a command
given to computer to carry out a particular operation on the data. In simple, instruction
specifies what to do with the data.
Ex: - 2+3
Here 2 & 3 are the data and instruction is addition operation (+)
Process:-
It is the actual interpretation and execution of the instruction on data. This is carried
out by the computers processing unit (Microprocessor) to obtain the required result. Here,
2, 3 and 4 is the data and the process to be carried out is to first take out the sum of 2 & 3
and from the result of the summing process subtract the value of 4.
Output:-
The first result obtained from the process the data according to the required result.
This result is known as output.
Ex: - 2+3-4
The result is 1
Information:-
Meaningful output is information. When we apply some process on data we get
some result. This result is called output But If that output is meaningful for someone, and
then it becomes information for him/her.
Ex: -
The average performance of a class is derived as an output from the process of
summing up all the marks of the class and dividing it by the number of students. This output
would be meaningful to the class teacher, but may not be the peon of the school. The
output derived is information for the class teacher but not the peon.
Knowledge:-
Knowledge is what we know about a particular domain (field). It is usually based on
learning, thinking and proper understanding of the problem area. Knowledge is derived
from information is derived from data. It refers to the use of information to make decisions.
Let us clear the difference between data, information and knowledge with an
example.
Ex: -
Data: 30,000, 7000, 18000, 9000
Information: Here is a price list of Nokia mobile phones
Nokia Lumia 920 30000
Nokia C5 7000
Nokia N8 18000
Nokia E5 9000
Knowledge: I only have Rs. 7000 to spend and can therefore only offered Nokia C5.
Database Management System Unit - 1
Prepared By Page 3
Mr. D. Sulthan Basha Lecturer in Computer Science
1.2 Data Vs Information
Data Information
1.Data is raw fact and figures
For Example: - 32 is data.
1.Information is a processed form of data
For example: - age 32.
2.Data is not significant to a business 2. Information is significant to a business.
3. Data are atomic level pieces of
information. It can be in the form of
numbers, characters, symbols, or even
pictures.
3. Information is a collection of data.
For Ex: - age and 32 collected together to form
information (age 32).
4. Data does not help in decision
making.
4. Information helps in decision making.
5. Observations and recordings are done
to obtain data.
5. Analysis is done to obtain information.
6. Input to any system may be treated
as data.
6. Output after processing the system is
information.
7. Difficult to understand properly. 7. Easy to understand.
8. Data must be processed to
understand.
8. Information is already in understandable
form, it may be processed further to make it
more understandable.
9. Data may not be in the order. 9. Information should be in the order.
1.3 Database Introduction
Data is a very important resource in the operation and the management and
organization. So it is very essential to organize the data in a meaningful manner, because an
organized data has no meaning. With the increased demand of the data in the various
organizations such as banks, universities, railways, airlines, companies etc, it becomes a
necessity to store data in an organized manner so that it can be used again and again. So we
need a Database to store the data in an organized form.
Database can be defined as “well organized collection of data that are related in a
meaningful way, which can be accessed by different uses but stored only once”.
To understand the concept of Database, Let us consider an example of telephone
directory in which names of people are arranged in an alphabetical order. So it becomes
easier to search any phone number corresponding to a particular name. If this ordering is
not done in an organized manner then it is very difficult to search s phone number of a
particular person, so this shows why Databases are needed.
Database Management System Unit - 1
Prepared By Page 4
Mr. D. Sulthan Basha Lecturer in Computer Science
Some other examples of Database are the dictionary, student’s record register, address
book etc.
1.3.1 Database Operations
To maintain hue Databases we need certain operations which help in maintaining
the data in the Database efficiently. The most commonly used operations: operations
performed on Database are:
1. Insertion: - To add new data into the Database for example to add new phone number
into telephone directory.
2. Selection: - To view (or) retrieve the stored data for example to view a telephone number
of a particular person from the telephone directory.
3. Updating: - To modify (or) edit the existing data for example. Suppose the phone number
of a particular person is changed so we have to modify the telephone directory by replacing
the old phone number with a new phone number.
4. Deletion: -To remove (or) delete the existing data from the Database. For example,
Suppose an employee has left the organization, so his record should be deleted from the
employee of Database of organization.
5. Sorting: - To arrange a data in a desired order (ascending/descending). For example
Database of an organization, records should be arranged in an alphabetical order. for easy
and fast retrieval.
1.3.2 Database Application
The collection of data usually referred to as the Database, contains information
relevant to an enterprise. Today, Database systems are widely used to manage large bodies
of information. Some of the important Database applications are:
Banking: - For customer information, accounts, loans, and banking Transactions.
Universities: - For student information, course registration, results and grades.
Data-1
Data-2
Data-n
Database
Related
to
each
other
User-1
User-2
User-n
Database Management System Unit - 1
Prepared By Page 5
Mr. D. Sulthan Basha Lecturer in Computer Science
Airlines: - For reservation and schedule information airlines were among the first to use the
Databases in a geographically distributed manner-Terminals situated around the world
accessed the central Database system through phone lines and other data Networks
Credit card Transaction:- For purchases on credit cards and generation of monthly
statements.
Sales: - For customer, product, and purchase information.
Tele Communication: - For keeping records of calls made, generating monthly bills,
maintaining balances on prepaid calling cards, and storing information about the
communication networks.
Manufacturing: - For tracking production of items in factories, inventories of items in ware
houses/stores, and orders for items.
Human resources: - For information about employees, salaries and payroll taxes.
1.4 File Based Systems
File based system was an early attempt to computerize the manual filing system. It is
basically a collection of application programs that performed services for the end users.
Each program within a file based system defines and manages its own data. In this system, a
large number of files are needed to perform various tasks. For example: In sales department
of enterprise, one user will be maintaining the details of how many sales persons are there
in the sales department and their grades, these detains will be stored and maintained in a
separate file. Another user will be maintaining the sales person salary details working in the
concern, the detailed salary report will be stored and maintained in a separate file. Although
both of the users are interested in the data’s of the sales persons, they will be having their
details in separate files. And they need different programmers to manipulate their files. This
will lead to wastage of space and redundancy or replication of data which may lead to
confusion, sharing of data among various users is not possible, data inconsistency may
occur.
This approach to data management, in which separate data files are created and stored
for each application program is called the “Traditional file approach”.
1.4.1 Characteristics of file Based System
Some Important characteristics of file based system are:
 It is a group of files storing data of an organization.
 Each file is independent from another file.
 Each file is called a flat file.
 Each file contained and processed information for one specific task, such as
accounting or inventory.
 Files are designed by using programs written in programming languages such as C &
C++.
 Each file must have its own file management system.
 As systems became more complex, file system approach offered little flexibility,
presented many limitations, and was difficult to maintain.
Database Management System Unit - 1
Prepared By Page 6
Mr. D. Sulthan Basha Lecturer in Computer Science
1.4.2 Draw Backs of file Based Systems
File based systems has following drawbacks:
1. Data Redundancy
2. Data Inconsistency
3. Data Isolation
4. Integrity Problems
5. Atomicity Problems
6. Concurrent axis variation
7. Security Problems
Data Redundancy:-
Data Redundancy means duplication of data values i.e. same information is
duplicated in several files. This makes data redundancy and is wasteful. It costs time and
money to enter the data more than once and also take up additional storage space.
Data Inconsistency:-
Data inconsistency means different copies of the same data are not matching. That
means different versions of same basic data are existing in different files. This occurs as the
result of update operations that are not updating the same data stored at different places.
Ex: - Address information of a customer is recorded differently in different files.
Data Isolation: -
Data are scattered in various files, and the files may be in different format, writing
new application program to retrieve data is difficult.
Integrity Problems:-
The data values may need to satisfy some integrity constrains. For Ex:- balance field
value must be greater than 5000. We have to handle this through program code in file
processing systems. But in Database we can declare the integrity constrains along with
definition itself.
Atomicity Problem:-
It is difficult to ensure atomicity in file processing system.
For Example: Transforming rs100 from account A to account B. If a failure occurs during
execution there could be situation like rs100 is calculated from account A and not credited
in account B.
Concurrent Access Variation:-
If multiple users are updating the same data simultaneously it will result in
inconsistence data state. In file processing system, It is very difficult to handle this using
program code. This results in concurrent access variation.
Security problems:-
Enforcing security constrains in file processing system is very difficult as the application
programs are added to the system in an unplanned or informal manner.
Database Management System Unit - 1
Prepared By Page 7
Mr. D. Sulthan Basha Lecturer in Computer Science
1.5 Database System
In order to remove all the limitations of a file based system, a new approach was
required that must be more effective so the concept of Database was introduced. This
approach is known as Database approach.
A database is a computer based record keeping system whose overall purpose is to
record and maintains information. The database is a single large repository which can be
used simultaneously by many departments and users. With the database approach, instead
of disconnected files with minimum amount of duplication and maintained only at one
location. In this approach, related data is shared by multiple application programs.
1.4.3 Characteristic of database system:
A database approach has the following characteristics
1. It is central repository of shared data. It allows several users to access the database
concurrently.
2. A fundamental feature of the database approach is that database system does not only
contain the data but also the complete definition and description of these data.
3. 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)
4. A primary feature of the database approach is a standardized uniform approach to
database access.
5. Data should be correct with respect to the real world entity that their represent.
6. Data should be protected from unauthorized access.
7. Its organization is such that duplication of data is minimized.
8. Data in a database exist permanently until it is not explicitly deleted.
1.4.4 Drawbacks of database system
A database system has following drawbacks
1. Database & management system can be difficult to setup and operate.
2. Many decisions must be made correctly for the database management system to work
effectively.
3. In addition, users have to learn new processors to take full advantages of a database
management system.
4. Database management systems can be more expensive to purchase and operate.
5. Recovery is more complex.
6. Initial training required for all programmers and users.
Database Management System Unit - 1
Prepared By Page 8
Mr. D. Sulthan Basha Lecturer in Computer Science
1.6 Introduction to DBMS
DBMS stands for database management system.
As the name suggests the database management system consists of two parts. They are:
1. Database
2. Management system.
1. Database: To find what database is, we have to start from data, which is the basic
building block of any database management system.
(i) Data: It is a raw set of facts and figures associated with individual, an entity or an event.
(ii) Record: A record can be defined as a collection of related data items.
(iii) Table: Collection of related records makes a table. The columns of the table are called
fields, attributes or domains. The rows are called tuples or records. Table is also known as a
relation.
(iv) Database: Collection of related tables makes a database.
In a database data is organized strictly in row and column format. All the data items
with a single attribute are of the same data type.
2. Management System: A management system is a set of rows and procedures which help
us to create organize and manipulate the database. It also helps us to add, modify and
delete data items in the database. The management system is important because without
the existence of some kind of rules and regulations it is not possible to maintain the
database.
Definition of DBMS:
DBMS is a software used to manage database and its various operations like
insertion, obtain and deletion, retrieval. It enables users to store, modify and extract
information from a database as per the requirements. It acts as an intermediately between
the user and the database.
1.6.1 Objectives of DBMS
The major objectives of Database Management System are
1. Data Availability
2. Data Integrity
3. Data Security
4. Data Independence.
Data Availability: -
Data availability refers to the fact that the data are made available to large variety of users
in a meaningful format at reasonable cost so that the users can easily access the data.
Data Integrity: -
Data Integrity refers to completeness, Correctness and consistency of data. It ensures that
data entered into the database must be complete, accurate, valid and consistent. Integrity is
related to the quality of data which is maintained with the help of integrity constrains.
These constrains are the rules that are designed to keep data consistent and correct.
Database Management System Unit - 1
Prepared By Page 9
Mr. D. Sulthan Basha Lecturer in Computer Science
Data Security: -
Data security refers to the fact that only authorized can access the data. Data
security can be enforced by passwords. If two separate users or accessing a particular data
at the same time, the DBMS must not allow them to make conflicting changes.
The analysis of Database security includes not only services provided by a DBMS but
a wider range of issues associated with database and environment security.
Data Independence: -
DBMS supports the concept of data independence since it represents a system for managing
data separately from a programs use the data.
1.6.2 Evaluation of DBMS
File based system was the predecessor to the Database management of DBMS is as
follows.
1. Flat file system (1990’s - 1980’s)
2. Hierarchical data model (1970’s - 1990’s)
3. Network data model (1970’s – 1990’s)
4. Relational data model (1980’s – present)
5. Object oriented DBMS (1990’s – present)
6. Object relational DBMS (1990’s – present)
7. Data warehousing (1990’s – present)
8. Web-enabled (1990’s – present)
Early 1960’s:
Charles Bachman at GE created the first general purpose DBMS integrated data store. It
created the basis for the network model which was standardized by conference on data
system language.
Late 1960’s:
IBM developed the information management system it used am alternate model called
Hierarchical data model.
1970’s:
Edger F CODD, from IBM created the relational data model.
1976:
Peter hen presented entity relationship model, which is widely used in database design.
1980:
SQL developed by IBM, became the standard language for databases.
1980’s and 1990’s
IBM, Oracle, Informix and others developed powerful DBMS.
1.6.3 Advantages of DBMS
DBMS has following advantages
1. Minimized Redundancy
2. Elimination of Inconsistency
3. Sharing of data
4. Data Security
5. Flexibility of the system is improved
Database Management System Unit - 1
Prepared By Page 10
Mr. D. Sulthan Basha Lecturer in Computer Science
6. Standards can be enforced
7. Data Integrity
8. Provides backup and recovery
Minimized Redundancy:
The data in a DBMS is more concise because, as a general rule the information in it
appears just once. This reduces data redundancy, because redundancy is the problem of
storing the same data item more than once place. Minimizing redundancy can reduce the
cost of storing information on hard drives and other storage devices and wastage of time in
entering data again and again.
Elimination of Inconsistency:
In the file processing system information is duplicated throughout the system. So
changes made in one file may be necessary be carried over to another file. This may entire
database so that changes once made are reflected to all the tables where a particulars field
is stored.
Sharing of data:
In DBMS many users can share the same Database it they are connected through a
network.
Data Security:
We can restrict certain people from accessing the database or allow them to see
some portion of the database while blocking sensitive information.
Flexibility of the system is improved:
Since changes are often necessary to the contents of the data stored in any system,
these changes are made more easily in centralized database. Application programs need not
to be changed on changing the data in the database.
Standards can be enforced:
Since all access to the database must be through DBMS. So standards are easily
enforced. Standards may relate to the naming of data, format of data, structure of the data
etc.
Data Integrity:
Accurate, consistence, up to date, date is a sign of data integrity, DBMS, supports
data integrity. Data integrity means that the data contained in the database is both accurate
and consistence.
Provides backup and recovery:
Centralizing a database provides the schemes such as recovery and backup from
other failures including disk crash, power failures, software errors which may help the
database that existed prior to the occurrence of the failure.
Database Management System Unit - 1
Prepared By Page 11
Mr. D. Sulthan Basha Lecturer in Computer Science
1.6.4 Disadvantages of DBMS
DBMS has the following disadvantages
1. High Cost
2. Complexity of backup and recovery
3. Security threads
High Cost:
A significant disadvantage of the DBMS system is cost. As DBMS needs computers,
we have to invest a good amount in acquiring the hardware, software, installation facilities
and training of users.
Complexity of backup and recovery
Backup and recovery operations are complex in DBMS environment. We have to
keep regular backups because a failure can occur any time. Taking backup is a lengthy
process and the computers system cannot perform any other job at this time.
Security Threads:
Even with safeguards in place, it may be possible for some unauthorized users to
access the Database. So security system must be very robust.
1.6.5 Classification of DBMS
The database management systems can be classified into different categories on the
basis of several criteria such as the data model they are using, number of users they
support, number of sites over which the database is distributed, and the purpose they
serve.
Based on data Models:
Depending on the data model they use, the DBMS’S can be classified as hierarchical,
network and relational.
 Hierarchical DBMS organizes the data records in a tree structure i.e. Hierarchy of
parent-child relationship.
 Network DBMS organizes the data records liked to one another through pointers,
which is an association between two records.
 Relational DBMS organizes the data records in the form of table and relationships
among the tables are set using common fields.
Based on number of users:
Depending on the number of users the DBMS supports, it is divided into two
categories namely single user system and multiuser system.
 In single user system the database resides on one computer and is only accessed by
one user at a time.
 In multiuser system, multiple users can access the database simultaneously. In
multiuser DBMS the data is both integrated and shared.
Database Management System Unit - 1
Prepared By Page 12
Mr. D. Sulthan Basha Lecturer in Computer Science
Based on number of sights:
Depending on the number of sights over which the database is distributed, it is
divided into two types namely centralized and distributed.
 Centralized database systems run on a single computer system. Both the database
and DBMS software reside with the centralized system through a dummy terminal
connected to it for information retrieval.
 In distributed database system, the database and DBMS software are distributed
over several computers located at different sights. The computers communicate with
each other through various communication media such high speed networks or
telephone lines.
Distributed database can be further classified as Homogeneous and
Heterogeneous.
 In homogeneous distributed database system, all sights have identical DBMS
software, where as heterogeneous distributed database system includes
different sights use different DBMS software.
Based on the purpose:
Depending on the purpose the DBMS serves, it can be classified as general purpose
or specific purpose.
DBMS is a general purpose software system. It can be designed for specific purpose
such as airline or railway reservations. Such systems cannot be used for other applications.
These database system fall under the category of online transformation processing(OLTP)
systems. OLTP systems are specifically used for data entry and retrieval. It supports large
number of concurrent transactions without excessive delays. ATM is best example for OLTP.
1.6.6 ANSI/Spark data model (OR) Data Abstraction (OR) Levels of
Abstraction (OR) Three Level Architecture
The difference between logical and physical representation of data recognized in
1978 when ASNI/spark (American National Standard Institute/standard’s planning and
requirement committee)proposed a generalized frame work for database system. This
frame work provided a three - level architecture, three levels of abstraction at which the
database could be viewed.
Three – level architecture of DBMS:
The major purpose of a database system is to provide users with an abstract view of
the system. The system hides certain complex details from the user which is called data
Abstraction.
In DBMS the database can have different aspects to reveal if seem from different levels
of abstraction. The term abstraction means the amount of detail you want to hide. A
computer reveals the minimum of its internal details when seen from outside. We don’t
know what parts it is build with. This is the highest level of abstraction, meaning very few
details are visible. If we open the computer and look inside at the hard disk, motherboard,
CD drive and RAM, we are in middle level of abstraction.
Database Management System Unit - 1
Prepared By Page 13
Mr. D. Sulthan Basha Lecturer in Computer Science
If we move on to open the hard disk and examine its tracks, sectors and read – write
heads, we are at the lowest level of abstraction where no details are invisible. In the same
manner the database can also be viewed from different levels of abstraction to reveal
different levels of details.
External Level
In this database view maximum details about the database will be hidden from the user. At
external level, only the restricted portion of the database is available to end users, because
an end user doesn’t need to know everything about the structure of the entire database. It
implements highest level of data abstraction.
Conceptual level
This new will provide some more detail about the database to the user like structure
schema detail of the database. Conceptual level describes what data are stored in database
what relationship exists among those data. It implements middle level of data abstraction.
Internal level
This level is concerned with the physical storage of the data. It provides the internal view of
the actual physical storage of data. It deals with the description of how raw data items are
stored in the physical storage devices. It also describes size of the storage media the
location of items in the storage device and so on. It implements lowest level of abstraction.
1.6.7 Components of DBMS
DBMS acts as an interface between the user and the database. The user requests the
DBMS to perform various operations on the database. The components of DBMS perform
these requested operations on the database and provide necessary data to the users.
User-1 User-2 User-n
Logical Level
Physical Level
User Level / External Level
Conceptual Level / Middle Level
Low Level / Internal Level
Database Management System Unit - 1
Prepared By Page 14
Mr. D. Sulthan Basha Lecturer in Computer Science
A DBMS is composed of following four major components, Which co - ordinate with
each other form an effective database system.
1.Data
2.Hardware
3.Software
4.Users
Data:
It is a very important component of the database system. Most of the organization
generate, store and process large amount of data. The data acts as a bridge between the
machine parts i.e. hardware and software and the users access it through some applications
program.
Data may be of different types, they are user data and Meta data
 User data consist of a table of data called relation where columns are called records
(or) tuples.
 Meta data means “data about data”. It is a description about the structure of the
database system tables store the metadata which includes basic information about
the design of each table.
Hardware:
The hardware consists of the secondary storage devices, such as Magnetic disks,
optical disks, magnetic tapes etc. On which data is stored together. It also includes input
output devices, processors, main memory etc. which are used for storing and retrieving the
data in a fast and efficient manner.
Software:
The software part consists of DBMS which acts as a bridge between the user and the
database. It allows the users to interact with the database to insert, delete, update and
retrieving data. For performing these operations we can use the query language like SQL (or)
Application software such as visual basic, developer 2000 etc.
Users:
The users are the people who manage databases and perform different operations
on the databases in the database system. On the basis of the job requirements made by
them they are provided access to the database totally or partially.
The users of a database system can be classified in the following groups.
Naive Users:
Naive user have no knowledge of database system and about its any
supporting software. These users are mainly used for collecting the data on the
notebooks (or) on the predesigned forms and ATM user is in this categories. Naïve
user can work on any simple GUI base menu driven system.
Online User:
Online users are those who may communicate with the database directly via
an online terminal (or) indirectly via a user interface and application program. These
users are aware of the presence of the database system and may have acquired a
Database Management System Unit - 1
Prepared By Page 15
Mr. D. Sulthan Basha Lecturer in Computer Science
certain amount of expertise within the limited interaction permitted with a
database.
Application Programmer:
Application programmer are professionals who are responsible for
developing application programs i.e. program for a particular application. They can
also modify an existing program. Application programmer works according to some
instructions given by database administrator.
Database Administrator(DBA):
The DBA is single person or a group of person responsible for implementing
the database system within an organization. DBA is only the guardian of the
organization but not the owner of organization. The DBA has all the system privilege
allowed by the DBMS and can drunk and revoke levels of access to and from other
users.
End Users:
End users are preliminary computer based users. The function of these users
is only to operate the computer and feed the collected information in an application
program and to execute it according to the analyst requirements.
1.6.8 Database Architecture
Database Architecture describes the location of all the pieces of information that
make up the database application. The database architecture can be classified into following
types.
1. Single-Tier architecture
2. Two-Tier architecture
3. Three-Tier architecture
4. N-Tier architecture
I. Single-Tier Architecture:
Single-Tier architecture consists of a single computer that contains a database and a
front end to access the database.
Generally these type of system is found in small business there is one computer
which stores all of the companies data on single database. The interface is used to interact
with the database may be part of the database or another program which ties into the
database itself.
The systems are centralized and single tier, which means the DBMS software and the
data reside in one location and dumb terminals are used to access the DBMS.
DBMS Software
Data
Dumb Terminal
Dumb Terminal
Dumb Terminal
Database Management System Unit - 1
Prepared By Page 16
Mr. D. Sulthan Basha Lecturer in Computer Science
Single-tier architecture is equivalent of running an application on a personal
computer. All the required components to run the application are located within it.
Advantages:
 A single-tier system requires only one stand-alone computer.
 It also requires only one installation of software. This makes it the most cost
effective system.
Disadvantages:
 It can be used by only one user at a time.
 The single tier system is impractical for an organization which requires two or more
users to interact with the organization data at the same time.
II. Two-Tier Architecture:
Two-Tier Architecture consists of two systems, a client and a server. The database is
stored on the server, and the interface used to access the database is installed on the client.
The architecture of any client-server environment by definition atleast a two-tier
system, the client being the first tier and the server being the second tier. The client
requests services directly from server. In two-Tier computing model, the user interface runs
on the client and the database is stored on the server.
Client – Computer
(First – Tier)
Database Server
(Second – Tier)
Advantages:
 Least complicated to implement
 Tools are relatively inexpensive
 The Two-Tier client server provides much more attractive graphical user interface
(GUI) applications.
 Two-Tier architecture maintains a persistent Connection between the client and
database.
 It offers great deals of flexibility and simplicity in management.
Disadvantages:
 As the application development is done on client side, maintenance cost of
application, as well as client side tools etc is expensive.
 Software distribution procedure is complicated.
 PC’s are considered to be weak in terms of security i.e. they are relatively easy to
crack.
Database Management System Unit - 1
Prepared By Page 17
Mr. D. Sulthan Basha Lecturer in Computer Science
III. Three-Tier Architecture:
In Three-Tier architecture, the client request are handled by intermediate servers
which co-ordinate the execution of the client request with sub-ordinate servers. It adds
middle wars, which provides a way for clients of one DBMS to access data from another
DBMS.
Generally two-tier model Is used to access the data from one DBMS server. Another
method is distribution is to store several equivalent databases in different places, which is
termed as distributed database system.
Client – Computer
(First – Tier)
Application Server Database Server
(Second – Tier) (Third – Tier)
First-Tier: In this tier, client sends request for the information. The main responsibility of
this tier is to receive user events and to control user interface and presentation of the data.
Second-Tier: The complex application logic is loaded here and available to the client tier on
request from client. These tier can protect the direct access of data.
Third-Tier: The Third-Tier contains the data that is needed for the application i.e. this tier is
responsible for data storage. This server mostly operates on a relational database.
Advantages:
 Three-Tier architecture improves data integrity
 Security is improved since the client doesn’t have direct access to the database.
 Change management is easier and faster to execute, because program logic is
implemented on the centralized server.
Disadvantages:
 More complex than two-tier architecture because it is more difficult to build a three-
tier application compared to a two-tier application.
 The client does not maintain a persistence database connection.
 A separate proxy server may be required.
IV. N-Tier Architecture:
In Three-Tier architecture, each server performs a specialized task or service. A
server can use services from others servers in order to provide its own service. As a result
three-tier architecture is potentially an N-tier architecture.
Database Management System Unit - 1
Prepared By Page 18
Mr. D. Sulthan Basha Lecturer in Computer Science
To turn three-tier architecture into N-tier system, the middle tier can be allowed to
have multiple application objects rather than a single application. Each of these application
objects must have a well defined interface which allows them to contact and communicate
with one another.
Advantages:
 Overall performance has been improved.
 The business logic is centralized.
 Enhanced security levels is obtained.
 Provides many services to many clients.
Disadvantages:
 More complicated to design than two-tier and three-tier computing models.
 Reliability is more difficult to achieve.
 More difficult to maintain software.
Client – Computer
(First – Tier)
Application Server
Level-1 Level-2 Level-3 Level-4
1.6.9 Situations where DBMS is not necessary
It is also necessary to specify situations where it is not necessary to use a DBMS. If
file processing system is working well and if it takes more money and time to design a
database, it is better not to go for the DBMS. More over if only one person maintains the
data and that person is not skilled in designing a data as well as not comfortable in using a
DBMS then it is not advisable to go for DBMS.
DBMS is undesirable under following situations.
 DBMS is undesirable if the application is simple, well defined, and not expected to
change.
 Runtime over heads are not feasible because of real time requirements.
 Multiple accesses to data are not required.
Server
Server
Server
Server
Database Management System Unit - 1
Prepared By Page 19
Mr. D. Sulthan Basha Lecturer in Computer Science
1.6.10 DBMS vendors and their products
Some of the popular DBMS vendors and their corresponding products are listed in
the following table.
Vendors Products
1.Microsoft
1.(a) Access
(b) Excel
(c) SQL server
2.Oracle
2. (a) Oracle DBMS
(B) My SQL
3.IBM
3. (a) DB2
(B) Informix dynamic server
4. Sybase
4. (a) Adoptive server enterprise (ASE)
(b) Adoptive server Anywhere(ASA)
(C) Whatcom
1.6.11 Database administrator & Their Rolls and Responsibilities
Database Administrator:
One of the main reasons for using DBMS is to have central control of both the data
and the programs that access those data. A person who has such central control over the
database system is called a Database Administrator (DBA).
The DBA is a single person or a group of persons responsible for implementing the
database system within an organization. DBA is only the guardian of organization but not
the owner of the organization.
Roles and Responsibilities:
 The main responsible of DBA is to make co-operate data available to the end users
and the decision makers of an organization.
 DBA is responsible for the design, implementation, maintains and repair of an
organization’s database.
 DBA decides the information contains of the database. He decides the suitable
database file structure for arrangement of data.
 DBA compiles the whole data in a particular order and sequence.
 DBA decides which access strategy and technique should be used for accessing the
data.
 DBA also takes backups of the data on backup storage device so that if data can be
lost then it can be again recover and compiled.
 DBA interacts regularly with technical, applications and operational staff to ensure
database integrity and security.
 Creating new user ID, password etc, and also creating the access permissions.
 Controlling and monitoring user access to the database.
 DBA creates a security mechanism to prevent unauthorized access, accidental or
intentional handling of data that can cause security threats.
Database Management System Unit - 1
Prepared By Page 20
Mr. D. Sulthan Basha Lecturer in Computer Science
1.7 Data Models: -
A data model is s representation on of reality, real world objects and events, and their
associations.
Models are corner stone of design. Engineers build a model of a vehicle to
Workout any details before putting it into production. In the same manner system designers
develop models to explore ideas and improve the understanding of the database design.
Data model can be defined as an integrated collection of concepts that can be used
to describe the logical structure of the database including data type relationship between
data and constrains that should apply on the data.
Data Models are classified into mainly three types.
i) Hierarchical data model.
ii) Network data model.
iii) Relational data model.
Hierarchical data model:
 Hierarchical data model is one of the oldest database models from late 1950’s.
 The general shape of this model is like an organizational chart. The terms parent and
child are often used in describing a hierarchical model.
 This model used the tree as its basic structure. A tree is a data structure that consists
of hierarchy of nodes, with a single node called the root.
 The parent-to –child creates one-two-many relationship, but the child to parent
creates one to one relationship.
 In Hierarchical data model records are arranged in top down structure.
2.Network data model:
 The network data model was developed to overcome the limited scope of
Hierarchical model. Here multiple parent-child relationships are used.
 The network model uses a network structure, which is a data structure consisting of
nodes and branches.
 In this model there is no distinguishing between parent and child nodes as in
hierarchical model. Each node may be related to more than one node.
 The main difference of network model with hierarchical model is that a network
model permits a child node t have more than one parent nodes, where ad
hierarchical model doesn’t allows a child node to have multiple parent nodes.
University
Mathematics Computer Science
Library Computer Lab
Database Management System Unit - 1
Prepared By Page 21
Mr. D. Sulthan Basha Lecturer in Computer Science
3.Relational data model:
 The most popular data model in DBMS is the relational data model. The principles of
the relational model are first outlined by Dr. EF CODD in 1970.
 The relational model is considered as one of the most popular developments in the
Database technology because it can be used for representing most of the real world
objects and the relationship between them.
 In relational model data is organized in terms of rows and columns in a table known
as “Relation”. Each table is consists of rows also known as ‘tuples’ and columns also
known as ‘attributes’.
 The relational database relates or connects data in different tables through the use
of a common field or attribute.
 Relatively complex and efficient data structures can be created with the relational
data model.
University
Mathematics Computer Science
Library Computer Lab
Column /Attribute / Domain
Row /Record / Tuple
Table / Relation
Database Management System Unit - 2
Prepared By Page 22
Mr. D. Sulthan Basha Lecturer in Computer Science
UNIT-2
Entity Relationship Model:
Entity Relationship Model is a high level conceptual data model developed by Peter
Chen in 1976 to facilitate database design. Conceptual Modeling is an important phase in
designing a successful database. A conceptual data model is a set of concepts that describe
the structure of a database and associated retrieved and updating transaction on the
database.
A Basic component of ER Model is the entity relationship Moe diagram which is used
to visually represent data objects and relationships between them.
2.1 Features of the ER Model
 The ER diagram used for representing ER Model can be easily converted into
relations (tables) in relational Model.
 The ER Model is used for the purpose of good database design by the database
developer.
 It is helpful as a problem decomposition tool as it shows the entities and relationship
between those entities.
 It is very easy and simple to understand by various types of users and designers.
 It offers an effective frame work for integrating multiple applications.
2.2 The basic building blocks of entity relationship diagram
Entity relationship diagram is a graphical modeling tool to standardized tool ER
modeling can be carried out with the help of pictorial representation of entities, attributes
and relationships.
1.Entity:
Entity is a thing in the real world with an independent existence about which data is
to be collected and stored.
Entity Type or Entity Set:
It is a collection of entities that have same attributes.
Entities are classified into two types.
1.Weak entity
2.Strong entity
Weak entity:
Weak entity is one whose existence depends on other entity. An entity that
doesn’t has attribute which may act as key attribute is called weal entity. A weak
entity in ER diagram id represented by double outlined Box.
Database Management System Unit - 2
Prepared By Page 23
Mr. D. Sulthan Basha Lecturer in Computer Science
Example:
Employee ID, basic salary,
student course etc.
Strong entity:
Strong entity is one whose existence doesn’t depend on any other entity. An
entity that has an attribute which may act as key attribute is called strong entity. A
strong entity in ER diagram is represented by single outlined Box.
Note: - Entities are represented by Rectangles.
2.Attribute:
Attribute is a characteristic or property of an entity. Attributes are represented by
means of ellipses (or) ovals.
Attributes are classified into four types
1. Simple;/Atomic/single valued attribute
2. Composite attribute
3. Multi valued attribute
4. Derived attribute
Simple/Atomic/Single valued attribute:
An attribute that consists of a single atomic value. It cannot be further sub
divided. The graphical symbol for this attribute is:
Composite attribute:
An attribute that can be further sub divided into subparts or components.
The graphical symbol for these attribute is:
Multi valued attribute:
A multi valued attribute can have multiple values. The graphical symbol for
this attribute is:
Example:
A person may have multiple
phone numbers, multiple
degrees, multiple e-mail ID’s etc.
Example:
The address attribute can be
composed of components like
house number, street, city, pin
code etc.
Database Management System Unit - 2
Prepared By Page 24
Mr. D. Sulthan Basha Lecturer in Computer Science
Derived attribute:
An attribute that’s value is derived from other attributes. The graphical
symbol for this attribute is:
3.Relationship:
Relationship is an associated among the instances of one or more entity
types
Example:
A student enrolls in a course. Here “STUDENT” “COURSE” are two entities
and the relationship between them “Enrolls”.
Relationship can be discussed as following types
1.Unary relationship
2.Binary relationship
3.Ternary/Multi Relationship
Unary Relationship:
A Unary relationship is a relationship between the instance of the single entity type.
It is also called as recursive relationship.
Example:
Binary Relationship:
Binary Relationship is a relationship between the instances of two entity types. This
is the most common type of relationship encountered in data modeling.
Example:
Example:
Age, total marks, gross salary etc.
STUDENT COURSE
Enrolls
EMPLOYEE Manages
TEACHER STUDENT
Teaches
Database Management System Unit - 2
Prepared By Page 25
Mr. D. Sulthan Basha Lecturer in Computer Science
1 1
1 M
Ternary/Multi Relationship:
Ternary Relationship is a relationship among the instances of three entity type.
A relationship among the instances of more than three entity types is called Multi
Relationship.
Example:
2.3 Degree Of Relationship(cardinality)
The degree of a relationship is the number of entities associated with the relationship.
The degree of relationship is also called “cardinality”.
Cardinalities are classified into four types
1) One-to-One
2) One-to-Many
3) Many-to-One
4) Many-to-Many
One-to-One Relationship:
Only one entity of the first set is related to only one entity of the second set. For
example, A teacher teaches a student. Only one teacher is teaching only one student. This
can be expressed in the following diagram.
One-to-Many Relationship:
One-to-many Relationship only one entity of the first set is related to multiple
entities of the second set. For example, A teacher teaches students. This can be expressed in
the following diagram.
Many-to-One Relationship:
Multiple entities of the first set are related to only one entity of the second set. For
example teaches teach a student. Many teachers are teaching only one student. This can be
expressed in the following diagram.
STUDENT TEACHER
Learns
from
LIBRARY
TEACHER STUDENT
Teaches
TEACHER STUDENT
Teaches
Database Management System Unit - 2
Prepared By Page 26
Mr. D. Sulthan Basha Lecturer in Computer Science
M 1
M M
Many-to-Many Relationship:
Multiple entities of the first set are related to multiple entities of the second set. For
Example, Teachers teach students. Many Teachers are teaching many students. This can be
considered as a two way one-to-many relationship. This can be expressed in the following
diagram.
2.4. Developing An ER Diagram
Developing an ER diagram requires an understanding of the system and its
components. Let us take a very simple example.
A person eats an Ice cream
This is a description of a real world activity, and we may consider the above
statement has a written document.
Now we have to prepare the ER diagram. Before discussing the procedure, we have
to process the above statement a little. We can see that the sentence contains a subject
(person), and object (Ice cream) and a verb (eats) that defines the relationship between the
subject and the object. Consider the nouns as entities and the verb as relationship.
The above diagram shows how person and Ice cream are related. Now every person
must have a name, address, phone number, etc and every Ice cream has a manufacture,
flavor, price etc. Without these items the diagram is not complete. These items are known
as attributes and they must be included in ER diagram and connected ovals or ellipses.
TEACHER STUDENT
Teaches
TEACHER STUDENT
Teaches
PERSON ICE CREAM
Eats
PERSON ICE CREAM
Eats
Name Manufacturer Flavour
Address Phone No. Price
Database Management System Unit - 2
Prepared By Page 27
Mr. D. Sulthan Basha Lecturer in Computer Science
Now we can define at least two tables for this ER diagram.
1. PERSON 2. ICE CREAM
Name Address Phone No. Manufacturer Flavour Price
2.5 Advantages and Disadvantages of ER Model
 Advantages:
Following are the advantages of an ER Model
1. Conceptual Simplicity
2. Visual Representation
3. Effective Communication Tool
4. Integrated with Relational database Model.
Conceptual Simplicity:
ER Model represents the concepts of a database along with its entities and
relationships in an easy way. It becomes even easier to create and manage the complex
database designs by using ER Model.
Visual Representation:
ER Model provides a visual representation of data and the relationships among data.
It helps the database designers, programmers and end users to understand the structure of
data in an easy way. It also minimizes the data redundancy.
Effective Communication Tool:
The database designer can use ER Model to get different views of data. As seen by
programmers, managers and end users etc. ER Model works as an effective communication
tool to integrate the views.
Integrated with relational database Model:
ER Model is well integrated with the relational database Model. These integration
makes relational database design a very structured process.
 Disadvantages:
Following are the disadvantages of an ER Model.
1. Popular for High-level design
2. No Industry Standard
3. Limited Relationship Representation
Popular for high-level design:
The ER Model is especially popular for high level database design.
No Industry Standard:
There is no Industry Standard notation for development an ER diagram.
Development Relationship Representation:
ER Model represents Limited relationships among the entities.
Database Management System Unit - 2
Prepared By Page 28
Mr. D. Sulthan Basha Lecturer in Computer Science
Unique
attributes
of subtypes
2.6 Enhanced Entity Relationship Model (or) Extended ER Model
The ER Model has been introduced during 1970’s but the business environment has
changed dramatically. Since that time business relationships are more complex, as a result
the business data became more complex. So the researchers have continued enhancing of
ER diagrams. So that they can more accurately represents the complex data in business
environment. The term enhanced entity relationship Model is used to identify the Model
that has resulted from extending the original ER Model with new model construct.
The Most important new modeling constructs is sub type/super type relationship. This
facility allows to model a general entity type called super type. And then sub divided into
several entity types is called subtype. For example, the entity type employee can be
modeled as a super type with the sub types REGULAR, CONTRACT, CAUSAL. Each sub type
inherits attributes from its super types and in addition the sub types may have special
attributes of its own.
Super type and sub type Entities
Super type:
A General entity type that has a relationship with one or more subtypes is
called super type.
Sub type:
A sub grouping of entities in an entity type that is meaningful to the
organization and that shares common attributes or relationships from other sub
groupings.
A basic notation for representing sub type, super type relationship is
SUPER TYPE
Common
attributes to
share to the
subtypes
Sub types
Database Management System Unit - 2
Prepared By Page 29
Mr. D. Sulthan Basha Lecturer in Computer Science
Unique
attributes
of subtypes
From the above notation the super type is connected with a line to a circle, which is
connected by a line to each sub type that has been defined the “U” shaped symbol on each
line connecting sub type to the circle indicate that the sub type is a subset of the super type.
It also indicates the direction of the sub type, super type relationship. The attributes
that are shared by all entities are associated with the super type. The attributes that are
Unique to a particular sub type those are associated with that sub type.
Example:
2.7 Explain Generalization and Specialization
Generalization:
Generalization is a process of defining more general entity type from a set of more
specialized entity types. So generalization is called Bottom up process.
Consider the following entities CAR, TRUCK and MOTOR CYCLE.
EMPLOYEE
ID Name DOB
REGULAR CONTRACT CASUAL
Sal Exp Period Wage
Common
attributes to
share to the
subtypes
Sub types
Amt
CAR
ID Model
Make
Price No.of
Passengers
TRUCK
ID Model Make
Price
Load
Capacity
Cabin
Type
Database Management System Unit - 2
Prepared By Page 30
Mr. D. Sulthan Basha Lecturer in Computer Science
The generalization allows us to group entity types with common attributes, at the
same time the generalization pressure us to specify the specific attributes to their entity
types.
From the above example we have defined a general entity called VEHICLE with
common attributes. The specialized attributes are defined with their sub type entity set.
Specialization:
Specialization is process of defining one or more subtype of the super type
and forming super type sub type relationship. Each sub type is formed based on some
specialized properties consider the following ER diagram.
VEHICLE
ID
Model
Price
CAR TRUCK MOTOR CYCLE
No.of
Passengers
Cabin type No.of Gears
Load capacity
Make
MOTOR CYCLE
ID Model
Make
Price No.of
Gears
From these ER diagrams we are
having three entity types called CAR, TRUCK,
and MOTOR CYCLE. At this stage that data
modular intends represent these entities
separately. By examining closely, we can see
that the entity types are having the common
attributes; they are Id, Model, Make, and
Price. This fact suggests that each of the
three entity types belongs to a version of
more general entity type.
Database Management System Unit - 2
Prepared By Page 31
Mr. D. Sulthan Basha Lecturer in Computer Science
ISA
By applying specialization in the above concept we will get two sub type entity types
called manufactured part and purchased part.
2.8 ISA Relationship and Attribute Inheritance
ISA Relationship supports attribute Inheritance and relationship participation in the EER
diagram, the sub class relationship is represented by IS A relationship. Attribute inheritance
is the property by which sub class entities inherit values for all attributes of the super class.
For example take a group “person”. A person has name, d.o.b, Gender, etc. These
properties are common in all persons, human beings but in a company, persons can be
identified as employee, employees, customers, vendor based on what role they play in the
company similarly in a college database or a staff based on what role they play in college as
entities.
PART
P.Name Supplier
Cost
Weight
MF_Date
P.No
From this ER diagram the entity
type PART is having several attributes.
They are pin Number, Name, Supplier,
Weight, manufactured date and cost.
While discussing with users the
developers discovered that they are two
possible sources for PARTS. Some parts
are manufactured internally; others are
purchased from outside vendors.
PART
P.Name
Supplier
Cost
Weight
MF_Date
P.No
MANUFACTURED PART PURCHASED PART
PERSON
STUDENT TEACHER
It is to be observed
that the student and
the teacher inherit
some of the attributes
of the person.
Database Management System Unit - 2
Prepared By Page 32
Mr. D. Sulthan Basha Lecturer in Computer Science
2.9 Aggregation
Aggregation is a process when relation between two entities is treated as a single
entity foe example. The relation between “CENTER’’, “course” entities is acting as a single
entity in relation with the entity “VISITOR”.
2.10 Multiple Inheritance
A sub class with than one super class is called a shared sub class. A subclass inherits
attributes not only of its direct super class, but also of all its predecessor super class, that is
it has multiple inheritance a sub class can be sub class of more than one super class.
For example, consider a person in an educational Institution the person can be
employee, alumnus, and student. The employee entity can be staff or faculty. The student
can be a graduate or post graduate student. The post graduate student can be a teaching
assistant if the post graduate student is a teaching assistant, then he/she inherits the
characteristic of the faculty as well as student class. That is the teaching assistant sub class is
a sub class of more than one super class. This phenomenon is called multiple inheritance
and is shown in below diagram.
CENTER COURSE
Offer
VISITOR
Enquire
PERSON
EMPLOYEE STUDENT
UNDER
GRADUATE
STAFF FACULTY POST
GRADUATE
CLASS TEACHING ASST
Teach
Assist
Database Management System Unit - 2
Prepared By Page 33
Mr. D. Sulthan Basha Lecturer in Computer Science
2.11 Constraints on Specialization and Generalization
The Constrains on Specialization and Generalization can be classified into
1. Disjointness Constraint
2. Completeness Constraint
Disjointness Constraint:
The Disjointness constraint allows us to specify the whether an instance of a super
type may simultaneously be a member of two or more subtypes. In disjointness, we have
two categories.
(a) Overlap Constraint
(b) Disjoint Constraint
Overlap Constraint:
Overlap refers to the fact that the same entity instance may be a member of
more than one subclass of the specialization.
Example:
Consider the example of “ANIMAL” Entity, which can be further subdivided
into ‘LAND ANIMAL’ and ‘WATER ANIMAL’. Consider the example of frog and
crocodile which can live both land and water. Hence the division of animal into land
and water animals is an example of overlap constraints.
Disjoint Constraint:
Disjoint refers to the fact that the same entity instance may be a member of
only subclass of the specialization.
Example:
Consider the example of “CATA LOGUE”. The catalogue is a super class which
can be further subdivided into ‘Books’, ‘JOURNALS’, and ‘PERIODIALS’. This false
under disjointness because a book entity can be neither “JOURNAL” NOR
“PERIODICAL”.
ANIMAL
LAND ANIMAL WATER ANIMAL
O
CATALOGUE
BOOK PERIODICAL
d
JOURNAL
Database Management System Unit - 2
Prepared By Page 34
Mr. D. Sulthan Basha Lecturer in Computer Science
Completeness Constraint:
The completeness constraint addresses the question whether an instance of a super
type must also be a member of at least one sub type. In completeness, we have two
categories.
(a) Total Specialization
(b) Partial Specialization
Total Specialization:
Total completeness refers to the fact that every entity instance in the super
class must be a member of some sub classes in the specialization. With total
specialization, am instance of the super type must be a member of at least one sub
type.
Example:
Consider the example of ‘TEACHER’. The teacher is a general term, which can
be further specialized into ‘LECTURER’, ‘TUTOR’ and ‘DEMONSTRATOR’. Here every
member in the super class participates as a member of a sub class; hence it is an
example of total participation.
Partial specialization:
Partial Completeness refers to the fact an entity instance in the super class
need not be a member of any sub class in the specialization. With partial
specialization an instance of a super type may subtype.
Example:
Consider ‘PERSON’ specialization into ‘EMPLOYEE’ and ‘STUDENT’. This is an
example of partial specialization because they can be a person who is unemployed
and doesn’t study.
TEACHER
LECTURER DEMONSTRATOR
d
TUTOR
Name ID
Salary Hours worked
Double line
represents total
Participation
‘d’ represents
disjointness
PERSON
EMPLOYEE STUDENT
O
Single line
represents partial
Participation
‘O’ represents
Overlap
Name
ID
Database Management System Unit - 2
Prepared By Page 35
Mr. D. Sulthan Basha Lecturer in Computer Science
2.12 Entity Clusters
EER diagrams are difficult to read when they are many entities and relationship. One
possible solution is to group entities and relationships into entity clusters.
Entity cluster is a set of one or more entity types and associated relationships
grouped into a single abstract entity type. Entity cluster behaves like an entity types can be
further grouped to form a higher level entity cluster.
To understand entity cluster, consider the example of Hospital Management. In
Hospital, the ‘DOCTOR’ treats the “PATIENT”. The doctors are payed the ‘management’
which builds buildings or specialist like those with MS OR MD. The patient can be either
inpatient or outpatient. It is to be noted that only outpatient will be allotted bed. If we have
to represent these ideas, it can be done using EER diagrams as shown in below diagrams.
The above diagram is found to be complex; the same idea is represented using entity
clusters as shown in below diagram.
MANAGEMENT BUILDINGS
builds
appoints
DOCTOR treats PATIENT
No.of rooms
GENERAL
PHYSICIAN
SPECIALIST IN-PATIENT OUT-PATIENT
Specialization Patient ID
is assigned
to
BED
Bed No.
MANAGEMENT
DOCTOR HOSPITAL
PATIENT
employs manage
treats
In the above diagram entities as well as relationships
are clustered into simply entity set.
Database Management System Unit - 3
Prepared By Page 36
Mr. D. Sulthan Basha Lecturer in Computer Science
UNIT-3
Relational Model
Introduction:
The Relational data Model is the conceptual bases of relational data bases proposed
by Dr. EF CODD in 1970. The Relational Model is considered as one of the most popular
development in the database technology because it can be used for representing most of
the real world objects and the relationship between them.
The main construct for representing data in the relational model is a relation, where
each relation is a table with rows and columns. Relational database established a well
defined relationship between database tables. A well designed relational database should
eliminate data redundancy i.e. the same piece of data should not be store in more than one
place. This is because duplicate data not only waste storage spaces but also easily lead to
inconsistency. It should also ensure data integrity and accuracy.
3.1 Basic Concepts of Relational Model
The relational data model uses formal terms like attributes, Tuple, Relation,
domain, schema and keys to define its concepts.
Let us define each of these terms
Attribute:An attribute can be defined as a characteristic of data. A real world data feature
modeled in the database will be represented by an attribute.
Relation: A Domain describes the set of possible values that are all of the same type for a
given attribute. A value is the smallest unit of data in the relational model.
Domain: A Database schema is a formal description of all the database relations and all
the relationships existing between them.
Key: The Relation data model uses keys to define identifiers for a relation’s Tuples. A key
is an attribute of a table which helps to uniquely identify s row.
3.2 CODD Rules
In 1985, Dr. EF CODD published database system. The reason Dr many, vendors
were marking products as ‘relational’ even though those products did not meet
minimum relational standards.
Dr. E.F codd’s rules shown in below, that are reference for what a truly relational
database should be
I. Information
II. Guaranteed Access
III. Systematic treatment of Nulls
IV. Dynamic on-line catalog Based on the Relational model.
V. Comprehensive data sublanguage
VI. View updating
VII. High-level Insert, update and delete
VIII. Physical data Independence
Database Management System Unit - 3
Prepared By Page 37
Mr. D. Sulthan Basha Lecturer in Computer Science
IX. Logical data Independence
X. Integrity Independence
XI. Distribution Independence
XII. Non sub version
Information:
All Information in a relational database must be logically represented as
column values in rows with in tables.
Guaranteed Access:
Every value in a table is guaranteed to accessible through a combination of
table name, primary key value and column name.
Systematic treatments of Nulls:
Nulls must be represented and treated in a systematic way, independent of
data type.
Dynamic on line catalog based on the Relational Model:
The Metadata must be stored and managed as ordinary data that is, in the
tables within the database. Such data using the standard database relational
languages.
Comprehensive Data sublanguage:
The Relational database may support many languages. However it must
support one well defined, declaration language with support for data definition, view
definition, data manipulation, integrity constraints, authorization, and transaction
management.
View Updating:
Any view that is theoretically updatable must be updatable through the
system.
High-level Insert, update and delete:
The database must support set-level inserts, updates, and deletes.
Physical data Independent:
Application programs and ad hoc facilities are logically unaffected when
physical access methods or storage structures are changed.
Logical data Independent:
Application programs and ad hoc facilities are logically unaffected when
changes are mades to the table structure preserve the original table values.
Integrity Independence:
All relational integrity constraints must be definable in the relational
language and stored in the system catalog not at the application level.
Distribution Independence:
The end users and application programs are unaware and unaffected by the
data location.
Database Management System Unit - 3
Prepared By Page 38
Mr. D. Sulthan Basha Lecturer in Computer Science
Non sub version:
If the system supports low-level access to the data, there must not be a way
to bypass the integrity rules of the database.
Rule Zero:
All preceding rules are based on the notation that in order for a database to
be considered relational, it must use its relational facilities exclusive to manage the
database.
3.3 Relational Integrity
 One of the most important responsibilities of a database administrator (DBS) is to
maintain the integrity of the database and prevent it from becoming corrupted.
 Database integrity means the completeness, correctness and consistency of data. It
ensures that data entered into the database must be complete, occurrence valid and
consistent. It is another form of database protection.
 In a Relational data model, data integrity or data accuracy can be achieved using
integrity rules or constraints. An integrity constraints is a condition that is specified
on a database schema, and characteristics and the data that can be stored in an
instance of the database.
Integrity constraints may be divided into three main categories
(i) Domain Integrity
(ii) Entity Integrity
(iii) Referential Integrity
Domain Integrity:
Domain Integrity rules are associated with maintaining the correctness of
validity of entries for a given column. We can enforce domain integrity by restricting
the type (through data types). The format ( through CHECK constraints and rules ) or
the range of possible values.
Entity Integrity:
Entity Integrity rules ensure that it should be easy to identify each entity in
the database. The entity integrity is a constraints on primary key value. It states key
that any attribute of a primary key cannot contain null value. If primary key contains
null values. It is not possible to uniquely identity a record in a relation.
Relational Integrity:
Referential Integrity rules are concerned with maintain the correctness and
consistency of relationships between relations. To define referential integrity
constraints it is necessary to define the foreign key first.
A foreign key is an attribute or a set of attributes within one relation that matches the
primary key of some other relation. In relational databases, sometimes it requires to ensure
that a value that appears in an relation for a given attributes (or a given set of attributes)
also appears for a certain attribute (or a certain set of a attributes) in another relation. This
is known as referential integrity constraints, which is expressed in terms of foreign keys.
Database Management System Unit - 3
Prepared By Page 39
Mr. D. Sulthan Basha Lecturer in Computer Science
3.4 Relational Keys in DBMS
A key is an attribute (also known as column/field or a combination of attributes
that is used to identity records. Sometimes we may have to retrieve data from more
than one table, in those cases we required to join tables with the help of keys. The
purpose of the key is to bind data together across tables without repeating all of the
data in every table.
The following are the types of keys.
i) Super key
ii) Candidate key
iii) Primary key
iv) Secondary key
v) Foreign key
Super key:
An attribute or a combination of attributes that are used to identify the
records uniquely is known as super key. A table can have many super keys.
Ex: Sno
Sno, sname
Eno, ename, address
Candidate key:
It can be defined as minimal super key. A super key that doesn’t contain a
subset of attributes that is itself a super key.
Ex: Sno, Sname etc
Primary key:
A candidate key that is used by the database designer for unique
identification of each row in a table is known as primary key.
Ex: sno
Eno
Prod_id
Secondary key:
An attribute or combination of attribute used strictly for data retrieval
purpose is called secondary key.
Ex: Sname, percentage
ename, address.
Foreign key:
A foreign key is an attribute or combination of attributes in one table that
points to the primary key of another table. The purpose of the foreign key is
to ensure referential integrity of the data.
Ex: Employee (emp-id, emp-name, emp-sal)
Department ( Dept-id, Dept-name, emp-id)
In the above example emp_id is the primary key for employee table
and foreign key for department table.
Database Management System Unit - 3
Prepared By Page 40
Mr. D. Sulthan Basha Lecturer in Computer Science
3.5 Null Values
If table contains no values for any field is a records, then that field is called
NULL value. If the column was created as NULLABLE, oracle will place a NULL value in
the column in the absence of a user defined value.
A NULL value is different from a blank or a zero. NULL values can be inserted
into the columns of any data type.
Principles of NULL values:
 Setting a NULL value is it would not be meaningful.
 A NULL value is not equivalent to a value of zero if the data type is number.
 A NULL value is not equivalent to spaces if the data type is character.
 A NULL value will evaluate to NULL in any expression, for example NULL multiplied
by 10 is NULL.
 NULL value can be inserted into columns of any data type.
 If the column has a NULL value, then no constraints will work on that column.
3.6 Relational Algebra
Every database management system must define a query language to allow
users to access the data stored in the database. Relational Algebra is a procedural
query language used to query the database tables to access data in different ways.
In Relational algebra, input is a relation (table from which data has to be
accessed) and output is also a relation ( a temporary table holding the data asked for
by the use). Relational algebra works on the whole table at once, so we do not have to
use loops etc to iterate overall the rows (tuples) of data one by one. All we have to do
is specify the table name from which we need the data, and in a single line of
Command, relational algebra will traverse the entire given table to fetch data for you.
3.6.1 Relational Algebra Operations
The primary operations that we can perform using relational algebra are:
1. Select
2. Project
3. Union
4. Set Different
5. Cartesian Product
6. Rename
Select Operations (σ):
This is used to fetch rows (tuples) from table (relation) which satisfies
a given condition.
Syntax: σp(r)
Where, σ represents the select predicate, r is the name of relation ( table
name in which you want to look for data), and p is the prepositional logic,
where we specify the conditions that must be satisfied by the data. In
Database Management System Unit - 3
Prepared By Page 41
Mr. D. Sulthan Basha Lecturer in Computer Science
prepositional logic, one can we unary and binary operators like =, <, > etc, to
specify the conditions.
Lets take an example of the ‘student’ table we specify above in the
introduction of relational algebra, and fetch data for students with age more
than 17.
σage>17(STUDENT)
This will fetch the tuples (rows) from ‘student’, for which ‘age’ will be
greater than 17. You can also use, and pr etc operators, to specify two
conditions, for example
σage>17 AND gender=’Male’(STUDENT)
This will return tuples (rows) from table student with information of
male students, of age more than 17.
Project Operation(π):
Project Operation is used to project only a certain set of attributes of
a relation. In simple words, if you want to see only the ‘names’ all of the
students in the ‘student’ table, then you can use project operations.
It will only project or show the columns or attributes asked foe, and
will also remove duplicate data from the column.
Syntax: πA1,A2(R)
Where A1, A2 etc are names of attributes (column names)
for example, πName, Age (STUDENT)
Above statement will show as only the ‘Name’ and ‘age’ columns for
all the rows of data in ‘Student’ table.
Union Operation(U):
This Operation is used to fetch data from two relations (tuples) or
temporary relation (result of another operation)
For this operation to work, the relations (tuples) specified should have
same number of attributes (columns) and same attribute domain. Also the
duplicate tuples are automatically eliminated from the result.
Where A and B are relations.
For Example, if we have two tuples ‘Regular class’ and ‘extra class’,
both have a column student to save name of student, then,
πstudent (REGULAR CLASS) U πstudent(EXTRA CLASS)
Above operation will give us name of ‘students’ who are attending
both regular classes and extra classes, eliminating repetition.
Database Management System Unit - 3
Prepared By Page 42
Mr. D. Sulthan Basha Lecturer in Computer Science
Set Difference(-):
This operation is used to find data present in one relation and not
present in the second Relation, this operation is also application on two
relations, just like Union Operation.
Syntax: A-B
Where A & B are relations.
For Example, if we want to find name of students who attend the regular class but
not the extra class, then, we can use the below Operation:
πStudent(REGULAR CLASS)-πStudent(EXTRA CLASS)
Cartesian Product(X):
This is used to combine data from two different relations (tuples) into
one and fetch data from the combined relation.
Syntax: A*B
For example, if we want to find the information for REGULAR CLASS and EXTRACLASS
which are conducted during morning, then, we can use the following operations.
σtime=’Morning’(REGULAR CLASS X EXTRA CLASS)
Rename Operation (p)
This operation is used to rename the output relation for any query
operation which returns result like select, project etc, or to simply rename a
relation (table)
Syntax: p(Relation New, Relation old)
3.6.2 Relational calculus (TRC)
Contrary to Relational algebra which is a procedural query language to fetch
data and which also explains how it is done, ‘Relational Calculus’ is non-procedural
query language and has no description about how the query will work or the data
will be fetched. It only focuses on what to do, and not on how to do it.
Relational calculus exits in two forms:
1. Tuple Relational calculus
2. Domain Relational calculus
Tuple Relational Calculus:
In tuple relational calculus, we work on filtering tuples based on the given
condition.
Syntax: { T | condition }
In this form of relational calculus, we define a tuple Variable, specify the table
(relation) name in which the tuple is to be Searched for, along with a condition.
We can also specify column name using a dot operation, with the tuple
variable to only get a certain attributes (column) in result.
Database Management System Unit - 3
Prepared By Page 43
Mr. D. Sulthan Basha Lecturer in Computer Science
A lot of information, right! Given it some time to sink in a tuple variable is
nothing but a name, can be anything, generally we use a single alphabet for this, so
lets say T is a tuple variable.
To specify the name of the relation (table) in which we want to look for data,
we do following Relation (T), where T is out tuple variable.
For example if our table is ‘student’ we would put it as a student (T)
Then comes the condition part, to specify a condition applicable for a
particular attribute (column), we can use the . dot variable with the tuple variable to
specify it, like in table ‘student’, if we want to get data for students with age greater
than 17, then we can write it as:
T-age>17
Where T is our tuple variable putting it all together, if we want to use tuple
relational calculus to fetch names of students, from table ‘Student’ with age greater
than 17, then, for T being our tuple variable.
T.name/student (T) AND T. age>17
Domain Relational calculus (DRC):
In domain relational calculus, filtering is done based on the domain of the
attributes and not based on the tuple values.
Syntax:- { C1 C2, C3,………Cn /F(C1,C2, C3,…….C }
Where C1, C2, …..etc represents domain of attributes (column) and F defines the
formula including the condition for fetching data.
For example, {<name, age/student ^ age>17}
Again, the above query will return the names and ages of the students in the table
‘student’ who are older than 17.
3.6.3 Advantages of Relational Algebra
 The Relational algebra has solid mathematical background. The mathematical
background of relational algebra is the basis of many interesting developments
and theorems. If we have two expressions for the same operation and if the
expressions are proved to be equivalent, then a query optimizer can
automatically substitute the more efficient form.
 Relational algebra is a high level language which talks in terms of properties of
sets of tuples and not in terms of for-loops.
3.6.4 Limitations of Relational Algebra
 The Relational algebra cannot do arithmetic. For example, if we want to know
the price of 10l of petrol, by assuming a 10%. Increase in the price of the petrol,
which cannot be done using relational algebra.
 The Relational algebra cannot sort or print results in various formats. For
example, if we want to arrange the product name in the increasing order of their
price. It cannot be done using relational algebra.
Database Management System Unit - 3
Prepared By Page 44
Mr. D. Sulthan Basha Lecturer in Computer Science
 Relational algebra cannot perform aggregates. For example, if we want to know
how many staff members are working in a particular department. This query
cannot be performed using relational algebra.
 The Relational algebra cannot modify the database. For example, if we want to
increase the salary of all employees by 10%. This cannot be done using relational
algebra.
3.7 QBE:
QBE stands for “Query By Example”. In database of management systems, QBE refers
to a method of forming queries in which the database program displays a blank record with
a space for each field. You can then enter conditions for each field that you want to be
included in the query for example, if you want to find all records where the AGE field is
greater than 65, you would enter >65 in the AGE field blank.
QBE uses a terminal display with attributes names as table headings for queries. It is
very easy to list the entire schema, simply by scrolling information on the screen.
QBE was developed originally by IBM in the 1970S to help users in their retrieval of
data from a database. QBE represents a visual approach for accessing data in a database
through the use of query templates.
QBE can be considered as GUI (Graphical user interface) based on domain calculus.
QBE allows users to key in their input requests by filling in empty tables on the screen,
and the system will also display its response in tabular form.
QBE is user-friendly because the users are not required to formulate sentences for
query requests with rigid query-language syntax. In QBE the request is entered in the form
of tables whose skeletons are initially constructed by QBE.
QBE is easier to learn than formal query languages, such as the standard structured
query language (SQL).
Database Management System Unit - 4
Prepared By Page 45
Mr. D. Sulthan Basha Lecturer in Computer Science
UNIT-4
STRUCTURED QUERY LANGUAGE (SQL)
Introduction:
SQL is the standard language used to communicate with the database system.
Without SQL we cannot able to do any operation on the database. So SQL is called “Heart of
DBMS”.All the tasks related to dbms are performed though SQL i.e,creating tables,modifying
rows,deleting rows etc.
The name SQL pronounced as “ESS-CUE-ELL” or “SEQUEL”. The SQL language was
developed at SAN JOSE RESEARCH laboratory at IBM.IBM was implemented the language
called “SEQUEL” in the year 1970 and its name had been changed to SQL.
SQL is a high level language that provides a greater degree of abstraction than
procedural languages. All the communications to DBMS must be performed through
SQL.The SQL having four types of statements ,they are:
1.Data Definition Language(DDL)
2.Data Manipulation Language(DML)
3.Data Retrieval Language(DRL)
4.Data Control Language(DCL)
5.Transcation Control Language(TCL)
DDL:
By using DDL statements a user can create a table structure, modify & delete the
structure. DDL contains the following commands.
CREATE,ALTER ,DROP & RENAME
DML:
By using DML statements the user can able to insert, update, & delete the records in
a table . DML contains the following commands.
INSERT, UPDATE, &DELETE, TRUNCATE
DRL:
By using DRL statements the user can able to extracts the stored information from
the database table . DRL contains the following commands only.
SELECT
DCL:
By using DCL statements the database administrator can grant permissions on the
database and tables. In some cases the granted permissions can be revoked. DCL contains
the following commands.
GRANT & REVOKE
TCL:
By using TCL statements the user can able to store records permanently and retrieve
,restore the records which are deleted mistakenly. TCL contains the following commands.
COMMIT, ROLLBACK, & SAVEPOINT
Database Management System Unit - 4
Prepared By Page 46
Mr. D. Sulthan Basha Lecturer in Computer Science
4.1 DATA TYPES
While defining the columns, the user has to specify its datatype and its size. The SQL
supports the following datatypes
Char(n)
Number(n)
Number(n,d)
Varchar(n)
Varchar2(n)
DATE,LONG,RAWL LONG RAW
CHAR(N):
By using this datatype we can able to store character type of data. We can store a
maximum of 255 characters.
NUMBER(N):
By using this datatype we can able to store a 40 digited integer number.
NUMBER(N,D):
By using this datatype we can able to store a 40 digited read value. Here ‘n’ defines
the total number of digits including decimals,’d’ defines the decimal points in the number.
DATE:
By using this datatype, we can able to store date and time.
VARCHAR/VARCHAR2(N):
By using this datatype we can able to store variable length upto 2000 characters.
LONG(N):
By using this datatype we can able to store a variable length string of 2GB.
RAW/LONGRAW(N):
The RAW&LONGRAW are used to store binary data upto 240 bytes and 6535 bytes
respectively.
4.2 PERFOMING SQL COMMANDS
4.2.1 Create Table Statement:
This statements is used to create a structure of database table.
Syntax:-
CREATE TABLE <Table_name>(
Col_name1 Datatype(size),
Col_name2 Datatype(size),
.
.
.
Col_nameN Datatype(size);
From the above syntax a database table is created with defined columns.A table may have a
maximum of 254 columns. While defining the names of table and columns,the user has to
follow the below conditions.
Database Management System Unit - 4
Prepared By Page 47
Mr. D. Sulthan Basha Lecturer in Computer Science
 The column name or table name must be started with an alphabet.
 No special characters are allowed in between the column names and table names
except underscore(_) and dollar symbol($).
 The reserved words are not allowed for defining as names for column & table.
EXAMPLES OF TABLE CREATION:
CREATE TABLE STUDENT(
S.no Number(3),
Name Varchar2(15),
Class Char(6),
Age Number(2),
Fee Number(7,12));
4.2.2 INSERT STATEMENT :
The “Insert Statement” is used to insert rows into a table.
Syntax:
Insert INTO<Table_name>Values (col-1,col-2,col-3…….);
Example:
Insert into student values(1907,’ Afiya’,’BSC’,’19’,12000);
From the above syntax and examples we can insert total values in a row, while
defining the values, the non-numeric constants such as characters and strings has to be
enclosed under (b/w) single coats(‘ ‘);
INSERTING ROWS BY SPECIFYING THE COLUMN NAMES:
SYNTAX:-
Insert into table name(col_name1,col_name2…….,col_name-n) Values(col-1 value,col-2 value……);
Example:-
Insert into student (sno,Name,Age) Values(1907,’Afiya’,19);
INSERTING ROWS BY USING “&” IN INSERT STATEMENT:
Syntax:-
Insert into table_name values(&col_name1,&col_name2……..);
Example: Insert into student values(&sno,’&name’,’&class’,&age,&fee);
Enter value for sno:1907
Enter value for Name: Afiya
Enter value for class: BSC
Enter value for AGE:19
Enter value for Fee: 12000 (enter)
/(press slash & Enter key)
4.2.3 DISPLAYING ROWS WITH SELECT STATEMENT
The SELECT statement is used to display the rows and columns values on the screen
Syntax:- SELECT * from <table_name>;
Examples: SELECT * from STUDENT;
Database Management System Unit - 4
Prepared By Page 48
Mr. D. Sulthan Basha Lecturer in Computer Science
Q: Write an SQL statement to create a table for Employee and it contains the columns as
Eno,Ename,Basic_sal,and address. And insert 5 rows into the employee table .
CREATE TABLE EMPLOYEE(
Eno number(4),
Ename varchar2(10),
Basic_sal number(7,2),
Address char(8)
);
Insert into employee values(1501,’sonu’,10000,’gtl’);
Insert into employee values(1502,’neha’,10500,’atp’);
Insert into employee values(1503,’rahul’,10820,’knl’);
Insert into employee values(1504,’javeed’,40000,’gtl’);
Insert into employee values(1505,’sabiha’,50000,’gtl’);
4.2.4 DESCRIBING A TABLE
The DESCRIBE statement is used to view the table definitions on the screen.
Syntax 1: DESC <TABLE_NAME>
Synatx 2: DESCRIBE<TABLE_NAME>
Example: DESCRIBE EMPLOYEE
4.2.5 SPECIFYING A “DEFAULT VALUE “ FOR A COLUMN:-
By using “ default “ clause, we can supply a default value for a column. This default
value is supplied whenever a row is inserted without column values in the insert statement.
The “default” clause is used (or) defined in CREATE/ALTER Statement.
Syntax: <col_name Datatype(size) DEFAULT Value>
Example: CREATE TABLE EMPLOYEE(
ENO NUMBER(4),
ENAME VARCHAR2(10),BSAL NUMBER (7,12),
TA NUMBER(4), DEFAULT 2000,
DA NUMBER(4),DEFAULT 1000,
HRA NUMBER(4),DEFAULT 1500);
4.2.6 SELECTING SPECIFIED ROWS FROM A TABLE
By using the “SELECT” statement and “WHERE” clause,we can able to select the
specified number of rows from a table.
Syntax: SELECT * FROM <TABLE_NAME>
WHERE < CONDITION>;
Example:
SELECT * FROM STUDENT
WHERE GROUP=’BSC’;
Database Management System Unit - 4
Prepared By Page 49
Mr. D. Sulthan Basha Lecturer in Computer Science
4.2.7 SELECTING SPECIFIED COLUMNS FROM A TABLE
By using “SELECT” Statement, we can able to select the specified number of columns
from table.
Syntax: SELECT col-1,col-2,col-3,…….from <Table_name>;
Example: SELECT sno,sname from STUDENT;
4.2.8 EXPRESSIONS IN SELECT STATEMENT
By using the expression in SELECT statement we can able to create virtual columns
Syntax:- SELECT col-1,col-2,…..exp1,exp2……..
FROM<TABLE_NAME>
WHERE < CONDITION>;
Example: SELECT Sno,Sname,Sub1+Sub2+Sub3, (Sub1+Sub2+Sub3)/3 From STUDENT
WHERE Sno=1506;
4.2.9 ORDERING ROWS BY USING “ORDER BY” CLAUSE
The “ORDER BY” clause is used to extract the rows in an order i.e either in ascending
order/descending order.The ORDER BY clause should be defined with the “SELECT”
statement.
Syntax:- SELECT columns from <Table_name>
ORDER By col_name[ASCE/DESE]
WHERE <condition>;
Example: SELECT * from student
ORDER BY sname DESC
WHERE Group=’BSC’;
NOTE: In select statement ‘*’ is used for retrieving all the columns values of tables.
4.2.10 SUBSTITUTING VARIABLES
To take the input from a user,we can substitute variables in WHERE Clause. To
substitute variables we have to use to “&” symbol before variable.
Example: SELECT * from employee
WHERE Ename = ‘&Ename’;
From the above examples before executing the SELECT statement it prompts for the
user input. After giving the input the value is substituted with ‘&Ename’ and executes the
statement.
4.2.11 DELETE Statement
The DELETE statement is used to remove the rows from a table.
Syntax: DELETE from <Table_name>;
From the above syntax the DELETE statement deletes all rows from the table
In order to delete specified rows ,the following syntax can be used.
Database Management System Unit - 4
Prepared By Page 50
Mr. D. Sulthan Basha Lecturer in Computer Science
Syntax: DELETE from <Table_name>
WHERE <condition>;
Example: DELETE from student WHERE sno=1502;
4.2.12 TRUNCATE Statement:
The TRUNCATE statement is used to delete all rows permanently in a table.
Syntax: TRUNCATE Table<Table_name>;
Example: TRUNCATE TABLE Student;
4.2.13 ALTER TABLE Statement
The alter table statement is used to change the structure of existing table by adding
new columns & increasing the column width(or) changing the datatype of a column etc.
The ALTER TABLE uses two keywords. They are :
1. ADD
2. MODIFY
 The keyword “ADD” is used to add new columns to the table.
 The keyword “MODIFY” is used to change the datatype(or) size of an existing
column.
Syntax1: ALTER TABLE<Table_name> ADD(col-1 datatype,col-2 datytype,….);
Syntax2:
ALTER TABLE <Table_name> MODIFY(Existing_col_name Datatype to be changed);
Example:
1) ALTER TABLE Student ADD(Total_marks number(3));
2) ALTER TABLE Student MODIFY (Sname varchar2(30));
4.2.14 RENAME TABLE Statement
The RENAME TABLE Statement is used to change the name of the existing table
Syntax: RENAME <old_table_name> To <new_table_name>;
Example: RENAME Student to std;
4.2.15 DROP TABLE statement
This statement is used to delete on existing table permanently from database.
Syntax: DROPTABLE <Table_name>;
Example: DROP TABLE Student;
4.2.16 UPDATE statement:
The “UPDATE” statement is used to change the existing information Of a row (or)
multiple rows of a table.
Syntax: UPDATE <Table_name> SET Expression
WHERE<condition>;
Database Management System Unit - 4
Prepared By Page 51
Mr. D. Sulthan Basha Lecturer in Computer Science
Example: UPDATE Student SET Total_marks=sub1+sub2+sub3
WHERE Group=’BSC’;
NOTE: “SET” clause is used to define the attribute or column and the expression are changes
to occur in the relative rows.
4.3 LOGICAL OPERATORS
There are three logical operators in SQL that can be used in SQL sentences.
1. AND Operator
2. OR Operator
3. NOT Operator
AND opeartor:
The oracle engine will process all rows in a table and display the result only when all
of the conditions specified using the AND operator are satisfied.
Example1: SELECT * from product
WHERE profit-percent>=10 AND profit-percent<=20;
Example2: SELECT * FROM STUDENT
WHERE AVG>=75 AND AVG<=90;
OR operator:
The oracle engine will process all rows in a table and display the result only when
any of the conditions specified using the OR operator are satisfied.
Example: SELECT * from Employee
WHERE address =”GTL” OR ADDRESS=ATP;
NOT operator:
The oracle engine will process all rows on a table and display the result only when
none of the conditions specified using the NOT operator are satisfied.
Example1: SELECT * FROM EMPLOYEE
WHERE NOT(B-SAL=2000 (or) B-SAL=3000);
Example2: SELECT * FROM STUDENT
WHERE NOT MARKS=250;
4.4 BETWEEN,IN& LIKE OPERATOR
BETWEEN operator:
The BETWEEN operator is used to select rows that contains the values with in a
specified range.
Syntax: SELECT col_s from <table_name>
WHERE col BETWEEN lower_lmt AND Upper_lmt;
Example: SELECT * FROM STUDENT
WHERE avg BETWEEN 50 AND 60;
Database Management System Unit - 4
Prepared By Page 52
Mr. D. Sulthan Basha Lecturer in Computer Science
IN Operator:
The “IN” Operator used to slect rows that matches one of the values in a list.
Syntax: SELECT Col from <table_name>
WHERE col IN (List of values separated by commas);
Example: SELECT * FROM STUDENT
WHERE SNO IN (1501,1502,1503);
LIKE Operators:
The “LIKE” operator is used to select the rows that partially match a portion
of character. The LIKE operator uses two special characters to define the expression
that is “%” and “-“.The LIKE operator is used only with “characters” and “varchar2”
datatypes.The special character % defines one or more character.The special
character “-“ specifies a single character.
Syntax: SELECT cols from <table-Name>
WHERE col like expression;
Ex: Select * from student
WHERE sname LIKE ‘A%’;
4.5 THE ORACLE TABLE DUAL
DUAL is a small oracle work table,which consists of only one row and column,and
contains the value ‘x’ in that column.Besides arithmetic calculations,it also supports data
retrieval and its formatting.
When an arithmetic exercise is to be performed such as 2*2 or 4/2 etc,there really is no
table being referenced only numeric literals are being used.
To facilitate such calculations via a SELECT,Oracle provides a dummy table called
DUAL,against which SELECT statement that are required to manipulate numeric literals can
be fired,and output obtained.
Example: SELECT 2*2 from DUAL;
Output:
𝟐∗𝟐
𝟒
 The current date can be obtained from the table DUAL in the required format as
shown below.
SYSDATE: SYSDATE is a pseudo column that contains the current date and time. It requires
no arguments when selected from the table DUAL & returns the current date.
Example: SELECT sysdate from DUAL;
Output: SYSDATE _
25-Oct-2019
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science
Sulthan's DBMS for_Computer_Science

Mais conteúdo relacionado

Mais procurados

Database Systems - introduction
Database Systems - introductionDatabase Systems - introduction
Database Systems - introductionJananath Banuka
 
Unstructured multidimensional array multimedia retrival model based xml database
Unstructured multidimensional array multimedia retrival model based xml databaseUnstructured multidimensional array multimedia retrival model based xml database
Unstructured multidimensional array multimedia retrival model based xml databaseeSAT Journals
 
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READDBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READamitp26
 
Mi0034 –database management systems
Mi0034 –database management systemsMi0034 –database management systems
Mi0034 –database management systemssmumbahelp
 
Unit 2 rdbms study_material
Unit 2  rdbms study_materialUnit 2  rdbms study_material
Unit 2 rdbms study_materialgayaramesh
 
Corporate data handling
Corporate data handlingCorporate data handling
Corporate data handlingJaipal Dhobale
 
Unit 3 rdbms study_materials-converted
Unit 3  rdbms study_materials-convertedUnit 3  rdbms study_materials-converted
Unit 3 rdbms study_materials-convertedgayaramesh
 
chalenges and apportunity of deep learning for big data analysis f
 chalenges and apportunity of deep learning for big data analysis f chalenges and apportunity of deep learning for big data analysis f
chalenges and apportunity of deep learning for big data analysis fmaru kindeneh
 
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...Mark John Lado, MIT
 
Electronic Data Processing
Electronic Data ProcessingElectronic Data Processing
Electronic Data ProcessingAnjan Mahanta
 
Introduction & history of dbms
Introduction & history of dbmsIntroduction & history of dbms
Introduction & history of dbmssethu pm
 
DBMS topics for BCA
DBMS topics for BCADBMS topics for BCA
DBMS topics for BCAAdbay
 

Mais procurados (20)

Database Systems - introduction
Database Systems - introductionDatabase Systems - introduction
Database Systems - introduction
 
Unstructured multidimensional array multimedia retrival model based xml database
Unstructured multidimensional array multimedia retrival model based xml databaseUnstructured multidimensional array multimedia retrival model based xml database
Unstructured multidimensional array multimedia retrival model based xml database
 
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READDBMS FOR STUDENTS MUST DOWNLOAD AND READ
DBMS FOR STUDENTS MUST DOWNLOAD AND READ
 
Mi0034 –database management systems
Mi0034 –database management systemsMi0034 –database management systems
Mi0034 –database management systems
 
Fundamentals of DBMS
Fundamentals of DBMSFundamentals of DBMS
Fundamentals of DBMS
 
Unit 2 rdbms study_material
Unit 2  rdbms study_materialUnit 2  rdbms study_material
Unit 2 rdbms study_material
 
Corporate data handling
Corporate data handlingCorporate data handling
Corporate data handling
 
Unit 3 rdbms study_materials-converted
Unit 3  rdbms study_materials-convertedUnit 3  rdbms study_materials-converted
Unit 3 rdbms study_materials-converted
 
Dbms
DbmsDbms
Dbms
 
Database system
Database system Database system
Database system
 
chalenges and apportunity of deep learning for big data analysis f
 chalenges and apportunity of deep learning for big data analysis f chalenges and apportunity of deep learning for big data analysis f
chalenges and apportunity of deep learning for big data analysis f
 
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...
A WIRELESS DIGITAL PUBLIC ADDRESS WITH VOICE ALARM AND TEXT-TO-SPEECH FEATURE...
 
Lecture1-IS322(Data&InfoMang-introduction)
Lecture1-IS322(Data&InfoMang-introduction)Lecture1-IS322(Data&InfoMang-introduction)
Lecture1-IS322(Data&InfoMang-introduction)
 
Electronic Data Processing
Electronic Data ProcessingElectronic Data Processing
Electronic Data Processing
 
320 324
320 324320 324
320 324
 
Lab 1 (cs351) (computer tech &amp; c++)
Lab 1 (cs351) (computer tech &amp; c++)Lab 1 (cs351) (computer tech &amp; c++)
Lab 1 (cs351) (computer tech &amp; c++)
 
Managing knowledge
Managing knowledgeManaging knowledge
Managing knowledge
 
Introduction & history of dbms
Introduction & history of dbmsIntroduction & history of dbms
Introduction & history of dbms
 
DBMS topics for BCA
DBMS topics for BCADBMS topics for BCA
DBMS topics for BCA
 
Db lecture 1
Db lecture 1Db lecture 1
Db lecture 1
 

Semelhante a Sulthan's DBMS for_Computer_Science

Chapter 2 - Intro to Data Sciences[2].pptx
Chapter 2 - Intro to Data Sciences[2].pptxChapter 2 - Intro to Data Sciences[2].pptx
Chapter 2 - Intro to Data Sciences[2].pptxJethroDignadice2
 
Computer Data Processing And Representation 4
Computer Data Processing And Representation   4Computer Data Processing And Representation   4
Computer Data Processing And Representation 4Amit Chandra
 
Mi0034 database management systems
Mi0034  database management systemsMi0034  database management systems
Mi0034 database management systemssmumbahelp
 
DATABASE MANAGEMENT SYSTEMS.pdf
DATABASE MANAGEMENT SYSTEMS.pdfDATABASE MANAGEMENT SYSTEMS.pdf
DATABASE MANAGEMENT SYSTEMS.pdfNikitaKumari71
 
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...SakkaravarthiS1
 
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERS
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERSCOMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERS
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERSMakaha Rutendo
 
System Analysis and Design chap 1 to 8.docx
System Analysis and Design chap 1 to 8.docxSystem Analysis and Design chap 1 to 8.docx
System Analysis and Design chap 1 to 8.docxAmdework Belay
 
IRJET- Comparative Study of Efficacy of Big Data Analysis and Deep Learni...
IRJET-  	  Comparative Study of Efficacy of Big Data Analysis and Deep Learni...IRJET-  	  Comparative Study of Efficacy of Big Data Analysis and Deep Learni...
IRJET- Comparative Study of Efficacy of Big Data Analysis and Deep Learni...IRJET Journal
 
Unit i big data introduction
Unit  i big data introductionUnit  i big data introduction
Unit i big data introductionSujaMaryD
 
Database Management System ( Dbms )
Database Management System ( Dbms )Database Management System ( Dbms )
Database Management System ( Dbms )Kimberly Brooks
 
Types Of Database For Flat File Database
Types Of Database For Flat File DatabaseTypes Of Database For Flat File Database
Types Of Database For Flat File DatabaseChristina Valadez
 

Semelhante a Sulthan's DBMS for_Computer_Science (20)

Chapter 2 - Intro to Data Sciences[2].pptx
Chapter 2 - Intro to Data Sciences[2].pptxChapter 2 - Intro to Data Sciences[2].pptx
Chapter 2 - Intro to Data Sciences[2].pptx
 
8.DBMS.pptx
8.DBMS.pptx8.DBMS.pptx
8.DBMS.pptx
 
Computer Data Processing And Representation 4
Computer Data Processing And Representation   4Computer Data Processing And Representation   4
Computer Data Processing And Representation 4
 
Mi0034 database management systems
Mi0034  database management systemsMi0034  database management systems
Mi0034 database management systems
 
basis data 02.pptx
basis data 02.pptxbasis data 02.pptx
basis data 02.pptx
 
DATABASE MANAGEMENT SYSTEMS.pdf
DATABASE MANAGEMENT SYSTEMS.pdfDATABASE MANAGEMENT SYSTEMS.pdf
DATABASE MANAGEMENT SYSTEMS.pdf
 
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...DATABASE MANAGEMENT SYSTEMS  university course materials useful for students ...
DATABASE MANAGEMENT SYSTEMS university course materials useful for students ...
 
Unit3rd
Unit3rdUnit3rd
Unit3rd
 
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERS
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERSCOMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERS
COMPUTER OPERATIONS & PACKAGES NOTES & INTRODUCTION TO COMPUTERS
 
System Analysis and Design chap 1 to 8.docx
System Analysis and Design chap 1 to 8.docxSystem Analysis and Design chap 1 to 8.docx
System Analysis and Design chap 1 to 8.docx
 
U - 2 Emerging.pptx
U - 2 Emerging.pptxU - 2 Emerging.pptx
U - 2 Emerging.pptx
 
Lect 1-2
Lect 1-2Lect 1-2
Lect 1-2
 
ITFT- Dbms
ITFT- DbmsITFT- Dbms
ITFT- Dbms
 
IRJET- Comparative Study of Efficacy of Big Data Analysis and Deep Learni...
IRJET-  	  Comparative Study of Efficacy of Big Data Analysis and Deep Learni...IRJET-  	  Comparative Study of Efficacy of Big Data Analysis and Deep Learni...
IRJET- Comparative Study of Efficacy of Big Data Analysis and Deep Learni...
 
Unit i big data introduction
Unit  i big data introductionUnit  i big data introduction
Unit i big data introduction
 
Database 1 Introduction
Database 1   IntroductionDatabase 1   Introduction
Database 1 Introduction
 
Database Management System ( Dbms )
Database Management System ( Dbms )Database Management System ( Dbms )
Database Management System ( Dbms )
 
Lect 1-2 Zaheer Abbas
Lect 1-2 Zaheer AbbasLect 1-2 Zaheer Abbas
Lect 1-2 Zaheer Abbas
 
Dbms
DbmsDbms
Dbms
 
Types Of Database For Flat File Database
Types Of Database For Flat File DatabaseTypes Of Database For Flat File Database
Types Of Database For Flat File Database
 

Último

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsTechSoup
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformChameera Dedduwage
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3JemimahLaneBuaron
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxiammrhaywood
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfAyushMahapatra5
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfchloefrazer622
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introductionMaksud Ahmed
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdfSoniaTolstoy
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Disha Kariya
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfAdmir Softic
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room servicediscovermytutordmt
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactdawncurless
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactPECB
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Celine George
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxVishalSingh1417
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfsanyamsingh5019
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingTechSoup
 

Último (20)

Introduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The BasicsIntroduction to Nonprofit Accounting: The Basics
Introduction to Nonprofit Accounting: The Basics
 
A Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy ReformA Critique of the Proposed National Education Policy Reform
A Critique of the Proposed National Education Policy Reform
 
Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3Q4-W6-Restating Informational Text Grade 3
Q4-W6-Restating Informational Text Grade 3
 
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptxSOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
SOCIAL AND HISTORICAL CONTEXT - LFTVD.pptx
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Class 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdfClass 11th Physics NEET formula sheet pdf
Class 11th Physics NEET formula sheet pdf
 
Arihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdfArihant handbook biology for class 11 .pdf
Arihant handbook biology for class 11 .pdf
 
microwave assisted reaction. General introduction
microwave assisted reaction. General introductionmicrowave assisted reaction. General introduction
microwave assisted reaction. General introduction
 
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdfBASLIQ CURRENT LOOKBOOK  LOOKBOOK(1) (1).pdf
BASLIQ CURRENT LOOKBOOK LOOKBOOK(1) (1).pdf
 
Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..Sports & Fitness Value Added Course FY..
Sports & Fitness Value Added Course FY..
 
Key note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdfKey note speaker Neum_Admir Softic_ENG.pdf
Key note speaker Neum_Admir Softic_ENG.pdf
 
9548086042 for call girls in Indira Nagar with room service
9548086042  for call girls in Indira Nagar  with room service9548086042  for call girls in Indira Nagar  with room service
9548086042 for call girls in Indira Nagar with room service
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
Accessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impactAccessible design: Minimum effort, maximum impact
Accessible design: Minimum effort, maximum impact
 
Beyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global ImpactBeyond the EU: DORA and NIS 2 Directive's Global Impact
Beyond the EU: DORA and NIS 2 Directive's Global Impact
 
Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17Advanced Views - Calendar View in Odoo 17
Advanced Views - Calendar View in Odoo 17
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
Sanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdfSanyam Choudhary Chemistry practical.pdf
Sanyam Choudhary Chemistry practical.pdf
 
Advance Mobile Application Development class 07
Advance Mobile Application Development class 07Advance Mobile Application Development class 07
Advance Mobile Application Development class 07
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 

Sulthan's DBMS for_Computer_Science

  • 1.
  • 2.
  • 3. Database Management System (DBMS) paper-5 (Syllabus) Unit-1 Over view of Database management system: Introduction, file-Based system, Draw Backs of file-based system, Data and information, Database, Database management system, objectives of DBMS, Revolution of Database management system, classifications DBMS, DBMS approach, advantages of DBMS, ANSI /spark, data model, Data models, components and interfaces of Database management system, Database architecture, situations were where DBMS is not necessary, DBMS venders and their products. Unit-2 Entity Relationship Mode: Introduction, the building blocks of an unity relationship diagram, classification of entity sets, attribute classification, relationship degree, relationship classification, reducing ER diagram to tables, enhanced entity relationship model, generalization and specializations, Isa relationship and attribute Inheritance, multiple Inheritance, constraints on specialization and generalization, Aggregation and composition, entity clusters, connection types, advantage of ER modeling. Unit-3 Relational Model: Introduction, CODD rules, Relational data model, concept of key, Relational Integrity, Relational algebra/relational algebra operations, Advantages of Relational algebra, limitations of relational algebra, relational calculus, Tuple relational calculus, domain relational calculus, QBE. Unit-4 Structure 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, table truncation, imposition of constrains, joint operation, set operation, view, sub query, embedded SQL. Unit-5 PL/SQL:- Introduction, short coming in SQL, structure of PL/SQL,PL/SQL language elements, data types, operator precedence, control structure, steps to create a PL/SQL program, iterative control, cursors, steps to create cursor, procedure, function, packages, exception handling, Database triggers, types of triggers.
  • 4.
  • 5. Database Management System Unit - 1 Prepared By Page 1 Mr. D. Sulthan Basha Lecturer in Computer Science Unit-1 1.1 Introduction to Database Management System Data Processing:- The activity of processing data using a computer is called data processing (or) electronic Data processing (EDP). The ultimate goal of data processing is to transform data into information. It saves time, money and man power. Data Processing System:- Data is raw material used as input and information is processed data obtained as output of data processing. Being a data processing system computer has importance in providing in-depth knowledge of whatever is involved in processing the data. But before looking into that, we require to define some of the basic terms associated with it. Input:- Input refers to the data and instructions given to the computers. Data is a raw set of facts and figures associated with an individual, an entity, or an event. It is basically a collection of unorganized facts (or) concepts that does not convey any meaning. Data can be represented in various forms i.e. in figures, characters, symbols, pictures, audio, video etc. Data Capture Data Manipulate Data Output Results Information Data Symbols Words Images Videos Audio Numbers
  • 6. Database Management System Unit - 1 Prepared By Page 2 Mr. D. Sulthan Basha Lecturer in Computer Science Instruction:- Instruction specifies how the data is to be manipulated. It is basically a command given to computer to carry out a particular operation on the data. In simple, instruction specifies what to do with the data. Ex: - 2+3 Here 2 & 3 are the data and instruction is addition operation (+) Process:- It is the actual interpretation and execution of the instruction on data. This is carried out by the computers processing unit (Microprocessor) to obtain the required result. Here, 2, 3 and 4 is the data and the process to be carried out is to first take out the sum of 2 & 3 and from the result of the summing process subtract the value of 4. Output:- The first result obtained from the process the data according to the required result. This result is known as output. Ex: - 2+3-4 The result is 1 Information:- Meaningful output is information. When we apply some process on data we get some result. This result is called output But If that output is meaningful for someone, and then it becomes information for him/her. Ex: - The average performance of a class is derived as an output from the process of summing up all the marks of the class and dividing it by the number of students. This output would be meaningful to the class teacher, but may not be the peon of the school. The output derived is information for the class teacher but not the peon. Knowledge:- Knowledge is what we know about a particular domain (field). It is usually based on learning, thinking and proper understanding of the problem area. Knowledge is derived from information is derived from data. It refers to the use of information to make decisions. Let us clear the difference between data, information and knowledge with an example. Ex: - Data: 30,000, 7000, 18000, 9000 Information: Here is a price list of Nokia mobile phones Nokia Lumia 920 30000 Nokia C5 7000 Nokia N8 18000 Nokia E5 9000 Knowledge: I only have Rs. 7000 to spend and can therefore only offered Nokia C5.
  • 7. Database Management System Unit - 1 Prepared By Page 3 Mr. D. Sulthan Basha Lecturer in Computer Science 1.2 Data Vs Information Data Information 1.Data is raw fact and figures For Example: - 32 is data. 1.Information is a processed form of data For example: - age 32. 2.Data is not significant to a business 2. Information is significant to a business. 3. Data are atomic level pieces of information. It can be in the form of numbers, characters, symbols, or even pictures. 3. Information is a collection of data. For Ex: - age and 32 collected together to form information (age 32). 4. Data does not help in decision making. 4. Information helps in decision making. 5. Observations and recordings are done to obtain data. 5. Analysis is done to obtain information. 6. Input to any system may be treated as data. 6. Output after processing the system is information. 7. Difficult to understand properly. 7. Easy to understand. 8. Data must be processed to understand. 8. Information is already in understandable form, it may be processed further to make it more understandable. 9. Data may not be in the order. 9. Information should be in the order. 1.3 Database Introduction Data is a very important resource in the operation and the management and organization. So it is very essential to organize the data in a meaningful manner, because an organized data has no meaning. With the increased demand of the data in the various organizations such as banks, universities, railways, airlines, companies etc, it becomes a necessity to store data in an organized manner so that it can be used again and again. So we need a Database to store the data in an organized form. Database can be defined as “well organized collection of data that are related in a meaningful way, which can be accessed by different uses but stored only once”. To understand the concept of Database, Let us consider an example of telephone directory in which names of people are arranged in an alphabetical order. So it becomes easier to search any phone number corresponding to a particular name. If this ordering is not done in an organized manner then it is very difficult to search s phone number of a particular person, so this shows why Databases are needed.
  • 8. Database Management System Unit - 1 Prepared By Page 4 Mr. D. Sulthan Basha Lecturer in Computer Science Some other examples of Database are the dictionary, student’s record register, address book etc. 1.3.1 Database Operations To maintain hue Databases we need certain operations which help in maintaining the data in the Database efficiently. The most commonly used operations: operations performed on Database are: 1. Insertion: - To add new data into the Database for example to add new phone number into telephone directory. 2. Selection: - To view (or) retrieve the stored data for example to view a telephone number of a particular person from the telephone directory. 3. Updating: - To modify (or) edit the existing data for example. Suppose the phone number of a particular person is changed so we have to modify the telephone directory by replacing the old phone number with a new phone number. 4. Deletion: -To remove (or) delete the existing data from the Database. For example, Suppose an employee has left the organization, so his record should be deleted from the employee of Database of organization. 5. Sorting: - To arrange a data in a desired order (ascending/descending). For example Database of an organization, records should be arranged in an alphabetical order. for easy and fast retrieval. 1.3.2 Database Application The collection of data usually referred to as the Database, contains information relevant to an enterprise. Today, Database systems are widely used to manage large bodies of information. Some of the important Database applications are: Banking: - For customer information, accounts, loans, and banking Transactions. Universities: - For student information, course registration, results and grades. Data-1 Data-2 Data-n Database Related to each other User-1 User-2 User-n
  • 9. Database Management System Unit - 1 Prepared By Page 5 Mr. D. Sulthan Basha Lecturer in Computer Science Airlines: - For reservation and schedule information airlines were among the first to use the Databases in a geographically distributed manner-Terminals situated around the world accessed the central Database system through phone lines and other data Networks Credit card Transaction:- For purchases on credit cards and generation of monthly statements. Sales: - For customer, product, and purchase information. Tele Communication: - For keeping records of calls made, generating monthly bills, maintaining balances on prepaid calling cards, and storing information about the communication networks. Manufacturing: - For tracking production of items in factories, inventories of items in ware houses/stores, and orders for items. Human resources: - For information about employees, salaries and payroll taxes. 1.4 File Based Systems File based system was an early attempt to computerize the manual filing system. It is basically a collection of application programs that performed services for the end users. Each program within a file based system defines and manages its own data. In this system, a large number of files are needed to perform various tasks. For example: In sales department of enterprise, one user will be maintaining the details of how many sales persons are there in the sales department and their grades, these detains will be stored and maintained in a separate file. Another user will be maintaining the sales person salary details working in the concern, the detailed salary report will be stored and maintained in a separate file. Although both of the users are interested in the data’s of the sales persons, they will be having their details in separate files. And they need different programmers to manipulate their files. This will lead to wastage of space and redundancy or replication of data which may lead to confusion, sharing of data among various users is not possible, data inconsistency may occur. This approach to data management, in which separate data files are created and stored for each application program is called the “Traditional file approach”. 1.4.1 Characteristics of file Based System Some Important characteristics of file based system are:  It is a group of files storing data of an organization.  Each file is independent from another file.  Each file is called a flat file.  Each file contained and processed information for one specific task, such as accounting or inventory.  Files are designed by using programs written in programming languages such as C & C++.  Each file must have its own file management system.  As systems became more complex, file system approach offered little flexibility, presented many limitations, and was difficult to maintain.
  • 10. Database Management System Unit - 1 Prepared By Page 6 Mr. D. Sulthan Basha Lecturer in Computer Science 1.4.2 Draw Backs of file Based Systems File based systems has following drawbacks: 1. Data Redundancy 2. Data Inconsistency 3. Data Isolation 4. Integrity Problems 5. Atomicity Problems 6. Concurrent axis variation 7. Security Problems Data Redundancy:- Data Redundancy means duplication of data values i.e. same information is duplicated in several files. This makes data redundancy and is wasteful. It costs time and money to enter the data more than once and also take up additional storage space. Data Inconsistency:- Data inconsistency means different copies of the same data are not matching. That means different versions of same basic data are existing in different files. This occurs as the result of update operations that are not updating the same data stored at different places. Ex: - Address information of a customer is recorded differently in different files. Data Isolation: - Data are scattered in various files, and the files may be in different format, writing new application program to retrieve data is difficult. Integrity Problems:- The data values may need to satisfy some integrity constrains. For Ex:- balance field value must be greater than 5000. We have to handle this through program code in file processing systems. But in Database we can declare the integrity constrains along with definition itself. Atomicity Problem:- It is difficult to ensure atomicity in file processing system. For Example: Transforming rs100 from account A to account B. If a failure occurs during execution there could be situation like rs100 is calculated from account A and not credited in account B. Concurrent Access Variation:- If multiple users are updating the same data simultaneously it will result in inconsistence data state. In file processing system, It is very difficult to handle this using program code. This results in concurrent access variation. Security problems:- Enforcing security constrains in file processing system is very difficult as the application programs are added to the system in an unplanned or informal manner.
  • 11. Database Management System Unit - 1 Prepared By Page 7 Mr. D. Sulthan Basha Lecturer in Computer Science 1.5 Database System In order to remove all the limitations of a file based system, a new approach was required that must be more effective so the concept of Database was introduced. This approach is known as Database approach. A database is a computer based record keeping system whose overall purpose is to record and maintains information. The database is a single large repository which can be used simultaneously by many departments and users. With the database approach, instead of disconnected files with minimum amount of duplication and maintained only at one location. In this approach, related data is shared by multiple application programs. 1.4.3 Characteristic of database system: A database approach has the following characteristics 1. It is central repository of shared data. It allows several users to access the database concurrently. 2. A fundamental feature of the database approach is that database system does not only contain the data but also the complete definition and description of these data. 3. 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) 4. A primary feature of the database approach is a standardized uniform approach to database access. 5. Data should be correct with respect to the real world entity that their represent. 6. Data should be protected from unauthorized access. 7. Its organization is such that duplication of data is minimized. 8. Data in a database exist permanently until it is not explicitly deleted. 1.4.4 Drawbacks of database system A database system has following drawbacks 1. Database & management system can be difficult to setup and operate. 2. Many decisions must be made correctly for the database management system to work effectively. 3. In addition, users have to learn new processors to take full advantages of a database management system. 4. Database management systems can be more expensive to purchase and operate. 5. Recovery is more complex. 6. Initial training required for all programmers and users.
  • 12. Database Management System Unit - 1 Prepared By Page 8 Mr. D. Sulthan Basha Lecturer in Computer Science 1.6 Introduction to DBMS DBMS stands for database management system. As the name suggests the database management system consists of two parts. They are: 1. Database 2. Management system. 1. Database: To find what database is, we have to start from data, which is the basic building block of any database management system. (i) Data: It is a raw set of facts and figures associated with individual, an entity or an event. (ii) Record: A record can be defined as a collection of related data items. (iii) Table: Collection of related records makes a table. The columns of the table are called fields, attributes or domains. The rows are called tuples or records. Table is also known as a relation. (iv) Database: Collection of related tables makes a database. In a database data is organized strictly in row and column format. All the data items with a single attribute are of the same data type. 2. Management System: A management system is a set of rows and procedures which help us to create organize and manipulate the database. It also helps us to add, modify and delete data items in the database. The management system is important because without the existence of some kind of rules and regulations it is not possible to maintain the database. Definition of DBMS: DBMS is a software used to manage database and its various operations like insertion, obtain and deletion, retrieval. It enables users to store, modify and extract information from a database as per the requirements. It acts as an intermediately between the user and the database. 1.6.1 Objectives of DBMS The major objectives of Database Management System are 1. Data Availability 2. Data Integrity 3. Data Security 4. Data Independence. Data Availability: - Data availability refers to the fact that the data are made available to large variety of users in a meaningful format at reasonable cost so that the users can easily access the data. Data Integrity: - Data Integrity refers to completeness, Correctness and consistency of data. It ensures that data entered into the database must be complete, accurate, valid and consistent. Integrity is related to the quality of data which is maintained with the help of integrity constrains. These constrains are the rules that are designed to keep data consistent and correct.
  • 13. Database Management System Unit - 1 Prepared By Page 9 Mr. D. Sulthan Basha Lecturer in Computer Science Data Security: - Data security refers to the fact that only authorized can access the data. Data security can be enforced by passwords. If two separate users or accessing a particular data at the same time, the DBMS must not allow them to make conflicting changes. The analysis of Database security includes not only services provided by a DBMS but a wider range of issues associated with database and environment security. Data Independence: - DBMS supports the concept of data independence since it represents a system for managing data separately from a programs use the data. 1.6.2 Evaluation of DBMS File based system was the predecessor to the Database management of DBMS is as follows. 1. Flat file system (1990’s - 1980’s) 2. Hierarchical data model (1970’s - 1990’s) 3. Network data model (1970’s – 1990’s) 4. Relational data model (1980’s – present) 5. Object oriented DBMS (1990’s – present) 6. Object relational DBMS (1990’s – present) 7. Data warehousing (1990’s – present) 8. Web-enabled (1990’s – present) Early 1960’s: Charles Bachman at GE created the first general purpose DBMS integrated data store. It created the basis for the network model which was standardized by conference on data system language. Late 1960’s: IBM developed the information management system it used am alternate model called Hierarchical data model. 1970’s: Edger F CODD, from IBM created the relational data model. 1976: Peter hen presented entity relationship model, which is widely used in database design. 1980: SQL developed by IBM, became the standard language for databases. 1980’s and 1990’s IBM, Oracle, Informix and others developed powerful DBMS. 1.6.3 Advantages of DBMS DBMS has following advantages 1. Minimized Redundancy 2. Elimination of Inconsistency 3. Sharing of data 4. Data Security 5. Flexibility of the system is improved
  • 14. Database Management System Unit - 1 Prepared By Page 10 Mr. D. Sulthan Basha Lecturer in Computer Science 6. Standards can be enforced 7. Data Integrity 8. Provides backup and recovery Minimized Redundancy: The data in a DBMS is more concise because, as a general rule the information in it appears just once. This reduces data redundancy, because redundancy is the problem of storing the same data item more than once place. Minimizing redundancy can reduce the cost of storing information on hard drives and other storage devices and wastage of time in entering data again and again. Elimination of Inconsistency: In the file processing system information is duplicated throughout the system. So changes made in one file may be necessary be carried over to another file. This may entire database so that changes once made are reflected to all the tables where a particulars field is stored. Sharing of data: In DBMS many users can share the same Database it they are connected through a network. Data Security: We can restrict certain people from accessing the database or allow them to see some portion of the database while blocking sensitive information. Flexibility of the system is improved: Since changes are often necessary to the contents of the data stored in any system, these changes are made more easily in centralized database. Application programs need not to be changed on changing the data in the database. Standards can be enforced: Since all access to the database must be through DBMS. So standards are easily enforced. Standards may relate to the naming of data, format of data, structure of the data etc. Data Integrity: Accurate, consistence, up to date, date is a sign of data integrity, DBMS, supports data integrity. Data integrity means that the data contained in the database is both accurate and consistence. Provides backup and recovery: Centralizing a database provides the schemes such as recovery and backup from other failures including disk crash, power failures, software errors which may help the database that existed prior to the occurrence of the failure.
  • 15. Database Management System Unit - 1 Prepared By Page 11 Mr. D. Sulthan Basha Lecturer in Computer Science 1.6.4 Disadvantages of DBMS DBMS has the following disadvantages 1. High Cost 2. Complexity of backup and recovery 3. Security threads High Cost: A significant disadvantage of the DBMS system is cost. As DBMS needs computers, we have to invest a good amount in acquiring the hardware, software, installation facilities and training of users. Complexity of backup and recovery Backup and recovery operations are complex in DBMS environment. We have to keep regular backups because a failure can occur any time. Taking backup is a lengthy process and the computers system cannot perform any other job at this time. Security Threads: Even with safeguards in place, it may be possible for some unauthorized users to access the Database. So security system must be very robust. 1.6.5 Classification of DBMS The database management systems can be classified into different categories on the basis of several criteria such as the data model they are using, number of users they support, number of sites over which the database is distributed, and the purpose they serve. Based on data Models: Depending on the data model they use, the DBMS’S can be classified as hierarchical, network and relational.  Hierarchical DBMS organizes the data records in a tree structure i.e. Hierarchy of parent-child relationship.  Network DBMS organizes the data records liked to one another through pointers, which is an association between two records.  Relational DBMS organizes the data records in the form of table and relationships among the tables are set using common fields. Based on number of users: Depending on the number of users the DBMS supports, it is divided into two categories namely single user system and multiuser system.  In single user system the database resides on one computer and is only accessed by one user at a time.  In multiuser system, multiple users can access the database simultaneously. In multiuser DBMS the data is both integrated and shared.
  • 16. Database Management System Unit - 1 Prepared By Page 12 Mr. D. Sulthan Basha Lecturer in Computer Science Based on number of sights: Depending on the number of sights over which the database is distributed, it is divided into two types namely centralized and distributed.  Centralized database systems run on a single computer system. Both the database and DBMS software reside with the centralized system through a dummy terminal connected to it for information retrieval.  In distributed database system, the database and DBMS software are distributed over several computers located at different sights. The computers communicate with each other through various communication media such high speed networks or telephone lines. Distributed database can be further classified as Homogeneous and Heterogeneous.  In homogeneous distributed database system, all sights have identical DBMS software, where as heterogeneous distributed database system includes different sights use different DBMS software. Based on the purpose: Depending on the purpose the DBMS serves, it can be classified as general purpose or specific purpose. DBMS is a general purpose software system. It can be designed for specific purpose such as airline or railway reservations. Such systems cannot be used for other applications. These database system fall under the category of online transformation processing(OLTP) systems. OLTP systems are specifically used for data entry and retrieval. It supports large number of concurrent transactions without excessive delays. ATM is best example for OLTP. 1.6.6 ANSI/Spark data model (OR) Data Abstraction (OR) Levels of Abstraction (OR) Three Level Architecture The difference between logical and physical representation of data recognized in 1978 when ASNI/spark (American National Standard Institute/standard’s planning and requirement committee)proposed a generalized frame work for database system. This frame work provided a three - level architecture, three levels of abstraction at which the database could be viewed. Three – level architecture of DBMS: The major purpose of a database system is to provide users with an abstract view of the system. The system hides certain complex details from the user which is called data Abstraction. In DBMS the database can have different aspects to reveal if seem from different levels of abstraction. The term abstraction means the amount of detail you want to hide. A computer reveals the minimum of its internal details when seen from outside. We don’t know what parts it is build with. This is the highest level of abstraction, meaning very few details are visible. If we open the computer and look inside at the hard disk, motherboard, CD drive and RAM, we are in middle level of abstraction.
  • 17. Database Management System Unit - 1 Prepared By Page 13 Mr. D. Sulthan Basha Lecturer in Computer Science If we move on to open the hard disk and examine its tracks, sectors and read – write heads, we are at the lowest level of abstraction where no details are invisible. In the same manner the database can also be viewed from different levels of abstraction to reveal different levels of details. External Level In this database view maximum details about the database will be hidden from the user. At external level, only the restricted portion of the database is available to end users, because an end user doesn’t need to know everything about the structure of the entire database. It implements highest level of data abstraction. Conceptual level This new will provide some more detail about the database to the user like structure schema detail of the database. Conceptual level describes what data are stored in database what relationship exists among those data. It implements middle level of data abstraction. Internal level This level is concerned with the physical storage of the data. It provides the internal view of the actual physical storage of data. It deals with the description of how raw data items are stored in the physical storage devices. It also describes size of the storage media the location of items in the storage device and so on. It implements lowest level of abstraction. 1.6.7 Components of DBMS DBMS acts as an interface between the user and the database. The user requests the DBMS to perform various operations on the database. The components of DBMS perform these requested operations on the database and provide necessary data to the users. User-1 User-2 User-n Logical Level Physical Level User Level / External Level Conceptual Level / Middle Level Low Level / Internal Level
  • 18. Database Management System Unit - 1 Prepared By Page 14 Mr. D. Sulthan Basha Lecturer in Computer Science A DBMS is composed of following four major components, Which co - ordinate with each other form an effective database system. 1.Data 2.Hardware 3.Software 4.Users Data: It is a very important component of the database system. Most of the organization generate, store and process large amount of data. The data acts as a bridge between the machine parts i.e. hardware and software and the users access it through some applications program. Data may be of different types, they are user data and Meta data  User data consist of a table of data called relation where columns are called records (or) tuples.  Meta data means “data about data”. It is a description about the structure of the database system tables store the metadata which includes basic information about the design of each table. Hardware: The hardware consists of the secondary storage devices, such as Magnetic disks, optical disks, magnetic tapes etc. On which data is stored together. It also includes input output devices, processors, main memory etc. which are used for storing and retrieving the data in a fast and efficient manner. Software: The software part consists of DBMS which acts as a bridge between the user and the database. It allows the users to interact with the database to insert, delete, update and retrieving data. For performing these operations we can use the query language like SQL (or) Application software such as visual basic, developer 2000 etc. Users: The users are the people who manage databases and perform different operations on the databases in the database system. On the basis of the job requirements made by them they are provided access to the database totally or partially. The users of a database system can be classified in the following groups. Naive Users: Naive user have no knowledge of database system and about its any supporting software. These users are mainly used for collecting the data on the notebooks (or) on the predesigned forms and ATM user is in this categories. Naïve user can work on any simple GUI base menu driven system. Online User: Online users are those who may communicate with the database directly via an online terminal (or) indirectly via a user interface and application program. These users are aware of the presence of the database system and may have acquired a
  • 19. Database Management System Unit - 1 Prepared By Page 15 Mr. D. Sulthan Basha Lecturer in Computer Science certain amount of expertise within the limited interaction permitted with a database. Application Programmer: Application programmer are professionals who are responsible for developing application programs i.e. program for a particular application. They can also modify an existing program. Application programmer works according to some instructions given by database administrator. Database Administrator(DBA): The DBA is single person or a group of person responsible for implementing the database system within an organization. DBA is only the guardian of the organization but not the owner of organization. The DBA has all the system privilege allowed by the DBMS and can drunk and revoke levels of access to and from other users. End Users: End users are preliminary computer based users. The function of these users is only to operate the computer and feed the collected information in an application program and to execute it according to the analyst requirements. 1.6.8 Database Architecture Database Architecture describes the location of all the pieces of information that make up the database application. The database architecture can be classified into following types. 1. Single-Tier architecture 2. Two-Tier architecture 3. Three-Tier architecture 4. N-Tier architecture I. Single-Tier Architecture: Single-Tier architecture consists of a single computer that contains a database and a front end to access the database. Generally these type of system is found in small business there is one computer which stores all of the companies data on single database. The interface is used to interact with the database may be part of the database or another program which ties into the database itself. The systems are centralized and single tier, which means the DBMS software and the data reside in one location and dumb terminals are used to access the DBMS. DBMS Software Data Dumb Terminal Dumb Terminal Dumb Terminal
  • 20. Database Management System Unit - 1 Prepared By Page 16 Mr. D. Sulthan Basha Lecturer in Computer Science Single-tier architecture is equivalent of running an application on a personal computer. All the required components to run the application are located within it. Advantages:  A single-tier system requires only one stand-alone computer.  It also requires only one installation of software. This makes it the most cost effective system. Disadvantages:  It can be used by only one user at a time.  The single tier system is impractical for an organization which requires two or more users to interact with the organization data at the same time. II. Two-Tier Architecture: Two-Tier Architecture consists of two systems, a client and a server. The database is stored on the server, and the interface used to access the database is installed on the client. The architecture of any client-server environment by definition atleast a two-tier system, the client being the first tier and the server being the second tier. The client requests services directly from server. In two-Tier computing model, the user interface runs on the client and the database is stored on the server. Client – Computer (First – Tier) Database Server (Second – Tier) Advantages:  Least complicated to implement  Tools are relatively inexpensive  The Two-Tier client server provides much more attractive graphical user interface (GUI) applications.  Two-Tier architecture maintains a persistent Connection between the client and database.  It offers great deals of flexibility and simplicity in management. Disadvantages:  As the application development is done on client side, maintenance cost of application, as well as client side tools etc is expensive.  Software distribution procedure is complicated.  PC’s are considered to be weak in terms of security i.e. they are relatively easy to crack.
  • 21. Database Management System Unit - 1 Prepared By Page 17 Mr. D. Sulthan Basha Lecturer in Computer Science III. Three-Tier Architecture: In Three-Tier architecture, the client request are handled by intermediate servers which co-ordinate the execution of the client request with sub-ordinate servers. It adds middle wars, which provides a way for clients of one DBMS to access data from another DBMS. Generally two-tier model Is used to access the data from one DBMS server. Another method is distribution is to store several equivalent databases in different places, which is termed as distributed database system. Client – Computer (First – Tier) Application Server Database Server (Second – Tier) (Third – Tier) First-Tier: In this tier, client sends request for the information. The main responsibility of this tier is to receive user events and to control user interface and presentation of the data. Second-Tier: The complex application logic is loaded here and available to the client tier on request from client. These tier can protect the direct access of data. Third-Tier: The Third-Tier contains the data that is needed for the application i.e. this tier is responsible for data storage. This server mostly operates on a relational database. Advantages:  Three-Tier architecture improves data integrity  Security is improved since the client doesn’t have direct access to the database.  Change management is easier and faster to execute, because program logic is implemented on the centralized server. Disadvantages:  More complex than two-tier architecture because it is more difficult to build a three- tier application compared to a two-tier application.  The client does not maintain a persistence database connection.  A separate proxy server may be required. IV. N-Tier Architecture: In Three-Tier architecture, each server performs a specialized task or service. A server can use services from others servers in order to provide its own service. As a result three-tier architecture is potentially an N-tier architecture.
  • 22. Database Management System Unit - 1 Prepared By Page 18 Mr. D. Sulthan Basha Lecturer in Computer Science To turn three-tier architecture into N-tier system, the middle tier can be allowed to have multiple application objects rather than a single application. Each of these application objects must have a well defined interface which allows them to contact and communicate with one another. Advantages:  Overall performance has been improved.  The business logic is centralized.  Enhanced security levels is obtained.  Provides many services to many clients. Disadvantages:  More complicated to design than two-tier and three-tier computing models.  Reliability is more difficult to achieve.  More difficult to maintain software. Client – Computer (First – Tier) Application Server Level-1 Level-2 Level-3 Level-4 1.6.9 Situations where DBMS is not necessary It is also necessary to specify situations where it is not necessary to use a DBMS. If file processing system is working well and if it takes more money and time to design a database, it is better not to go for the DBMS. More over if only one person maintains the data and that person is not skilled in designing a data as well as not comfortable in using a DBMS then it is not advisable to go for DBMS. DBMS is undesirable under following situations.  DBMS is undesirable if the application is simple, well defined, and not expected to change.  Runtime over heads are not feasible because of real time requirements.  Multiple accesses to data are not required. Server Server Server Server
  • 23. Database Management System Unit - 1 Prepared By Page 19 Mr. D. Sulthan Basha Lecturer in Computer Science 1.6.10 DBMS vendors and their products Some of the popular DBMS vendors and their corresponding products are listed in the following table. Vendors Products 1.Microsoft 1.(a) Access (b) Excel (c) SQL server 2.Oracle 2. (a) Oracle DBMS (B) My SQL 3.IBM 3. (a) DB2 (B) Informix dynamic server 4. Sybase 4. (a) Adoptive server enterprise (ASE) (b) Adoptive server Anywhere(ASA) (C) Whatcom 1.6.11 Database administrator & Their Rolls and Responsibilities Database Administrator: One of the main reasons for using DBMS is to have central control of both the data and the programs that access those data. A person who has such central control over the database system is called a Database Administrator (DBA). The DBA is a single person or a group of persons responsible for implementing the database system within an organization. DBA is only the guardian of organization but not the owner of the organization. Roles and Responsibilities:  The main responsible of DBA is to make co-operate data available to the end users and the decision makers of an organization.  DBA is responsible for the design, implementation, maintains and repair of an organization’s database.  DBA decides the information contains of the database. He decides the suitable database file structure for arrangement of data.  DBA compiles the whole data in a particular order and sequence.  DBA decides which access strategy and technique should be used for accessing the data.  DBA also takes backups of the data on backup storage device so that if data can be lost then it can be again recover and compiled.  DBA interacts regularly with technical, applications and operational staff to ensure database integrity and security.  Creating new user ID, password etc, and also creating the access permissions.  Controlling and monitoring user access to the database.  DBA creates a security mechanism to prevent unauthorized access, accidental or intentional handling of data that can cause security threats.
  • 24. Database Management System Unit - 1 Prepared By Page 20 Mr. D. Sulthan Basha Lecturer in Computer Science 1.7 Data Models: - A data model is s representation on of reality, real world objects and events, and their associations. Models are corner stone of design. Engineers build a model of a vehicle to Workout any details before putting it into production. In the same manner system designers develop models to explore ideas and improve the understanding of the database design. Data model can be defined as an integrated collection of concepts that can be used to describe the logical structure of the database including data type relationship between data and constrains that should apply on the data. Data Models are classified into mainly three types. i) Hierarchical data model. ii) Network data model. iii) Relational data model. Hierarchical data model:  Hierarchical data model is one of the oldest database models from late 1950’s.  The general shape of this model is like an organizational chart. The terms parent and child are often used in describing a hierarchical model.  This model used the tree as its basic structure. A tree is a data structure that consists of hierarchy of nodes, with a single node called the root.  The parent-to –child creates one-two-many relationship, but the child to parent creates one to one relationship.  In Hierarchical data model records are arranged in top down structure. 2.Network data model:  The network data model was developed to overcome the limited scope of Hierarchical model. Here multiple parent-child relationships are used.  The network model uses a network structure, which is a data structure consisting of nodes and branches.  In this model there is no distinguishing between parent and child nodes as in hierarchical model. Each node may be related to more than one node.  The main difference of network model with hierarchical model is that a network model permits a child node t have more than one parent nodes, where ad hierarchical model doesn’t allows a child node to have multiple parent nodes. University Mathematics Computer Science Library Computer Lab
  • 25. Database Management System Unit - 1 Prepared By Page 21 Mr. D. Sulthan Basha Lecturer in Computer Science 3.Relational data model:  The most popular data model in DBMS is the relational data model. The principles of the relational model are first outlined by Dr. EF CODD in 1970.  The relational model is considered as one of the most popular developments in the Database technology because it can be used for representing most of the real world objects and the relationship between them.  In relational model data is organized in terms of rows and columns in a table known as “Relation”. Each table is consists of rows also known as ‘tuples’ and columns also known as ‘attributes’.  The relational database relates or connects data in different tables through the use of a common field or attribute.  Relatively complex and efficient data structures can be created with the relational data model. University Mathematics Computer Science Library Computer Lab Column /Attribute / Domain Row /Record / Tuple Table / Relation
  • 26. Database Management System Unit - 2 Prepared By Page 22 Mr. D. Sulthan Basha Lecturer in Computer Science UNIT-2 Entity Relationship Model: Entity Relationship Model is a high level conceptual data model developed by Peter Chen in 1976 to facilitate database design. Conceptual Modeling is an important phase in designing a successful database. A conceptual data model is a set of concepts that describe the structure of a database and associated retrieved and updating transaction on the database. A Basic component of ER Model is the entity relationship Moe diagram which is used to visually represent data objects and relationships between them. 2.1 Features of the ER Model  The ER diagram used for representing ER Model can be easily converted into relations (tables) in relational Model.  The ER Model is used for the purpose of good database design by the database developer.  It is helpful as a problem decomposition tool as it shows the entities and relationship between those entities.  It is very easy and simple to understand by various types of users and designers.  It offers an effective frame work for integrating multiple applications. 2.2 The basic building blocks of entity relationship diagram Entity relationship diagram is a graphical modeling tool to standardized tool ER modeling can be carried out with the help of pictorial representation of entities, attributes and relationships. 1.Entity: Entity is a thing in the real world with an independent existence about which data is to be collected and stored. Entity Type or Entity Set: It is a collection of entities that have same attributes. Entities are classified into two types. 1.Weak entity 2.Strong entity Weak entity: Weak entity is one whose existence depends on other entity. An entity that doesn’t has attribute which may act as key attribute is called weal entity. A weak entity in ER diagram id represented by double outlined Box.
  • 27. Database Management System Unit - 2 Prepared By Page 23 Mr. D. Sulthan Basha Lecturer in Computer Science Example: Employee ID, basic salary, student course etc. Strong entity: Strong entity is one whose existence doesn’t depend on any other entity. An entity that has an attribute which may act as key attribute is called strong entity. A strong entity in ER diagram is represented by single outlined Box. Note: - Entities are represented by Rectangles. 2.Attribute: Attribute is a characteristic or property of an entity. Attributes are represented by means of ellipses (or) ovals. Attributes are classified into four types 1. Simple;/Atomic/single valued attribute 2. Composite attribute 3. Multi valued attribute 4. Derived attribute Simple/Atomic/Single valued attribute: An attribute that consists of a single atomic value. It cannot be further sub divided. The graphical symbol for this attribute is: Composite attribute: An attribute that can be further sub divided into subparts or components. The graphical symbol for these attribute is: Multi valued attribute: A multi valued attribute can have multiple values. The graphical symbol for this attribute is: Example: A person may have multiple phone numbers, multiple degrees, multiple e-mail ID’s etc. Example: The address attribute can be composed of components like house number, street, city, pin code etc.
  • 28. Database Management System Unit - 2 Prepared By Page 24 Mr. D. Sulthan Basha Lecturer in Computer Science Derived attribute: An attribute that’s value is derived from other attributes. The graphical symbol for this attribute is: 3.Relationship: Relationship is an associated among the instances of one or more entity types Example: A student enrolls in a course. Here “STUDENT” “COURSE” are two entities and the relationship between them “Enrolls”. Relationship can be discussed as following types 1.Unary relationship 2.Binary relationship 3.Ternary/Multi Relationship Unary Relationship: A Unary relationship is a relationship between the instance of the single entity type. It is also called as recursive relationship. Example: Binary Relationship: Binary Relationship is a relationship between the instances of two entity types. This is the most common type of relationship encountered in data modeling. Example: Example: Age, total marks, gross salary etc. STUDENT COURSE Enrolls EMPLOYEE Manages TEACHER STUDENT Teaches
  • 29. Database Management System Unit - 2 Prepared By Page 25 Mr. D. Sulthan Basha Lecturer in Computer Science 1 1 1 M Ternary/Multi Relationship: Ternary Relationship is a relationship among the instances of three entity type. A relationship among the instances of more than three entity types is called Multi Relationship. Example: 2.3 Degree Of Relationship(cardinality) The degree of a relationship is the number of entities associated with the relationship. The degree of relationship is also called “cardinality”. Cardinalities are classified into four types 1) One-to-One 2) One-to-Many 3) Many-to-One 4) Many-to-Many One-to-One Relationship: Only one entity of the first set is related to only one entity of the second set. For example, A teacher teaches a student. Only one teacher is teaching only one student. This can be expressed in the following diagram. One-to-Many Relationship: One-to-many Relationship only one entity of the first set is related to multiple entities of the second set. For example, A teacher teaches students. This can be expressed in the following diagram. Many-to-One Relationship: Multiple entities of the first set are related to only one entity of the second set. For example teaches teach a student. Many teachers are teaching only one student. This can be expressed in the following diagram. STUDENT TEACHER Learns from LIBRARY TEACHER STUDENT Teaches TEACHER STUDENT Teaches
  • 30. Database Management System Unit - 2 Prepared By Page 26 Mr. D. Sulthan Basha Lecturer in Computer Science M 1 M M Many-to-Many Relationship: Multiple entities of the first set are related to multiple entities of the second set. For Example, Teachers teach students. Many Teachers are teaching many students. This can be considered as a two way one-to-many relationship. This can be expressed in the following diagram. 2.4. Developing An ER Diagram Developing an ER diagram requires an understanding of the system and its components. Let us take a very simple example. A person eats an Ice cream This is a description of a real world activity, and we may consider the above statement has a written document. Now we have to prepare the ER diagram. Before discussing the procedure, we have to process the above statement a little. We can see that the sentence contains a subject (person), and object (Ice cream) and a verb (eats) that defines the relationship between the subject and the object. Consider the nouns as entities and the verb as relationship. The above diagram shows how person and Ice cream are related. Now every person must have a name, address, phone number, etc and every Ice cream has a manufacture, flavor, price etc. Without these items the diagram is not complete. These items are known as attributes and they must be included in ER diagram and connected ovals or ellipses. TEACHER STUDENT Teaches TEACHER STUDENT Teaches PERSON ICE CREAM Eats PERSON ICE CREAM Eats Name Manufacturer Flavour Address Phone No. Price
  • 31. Database Management System Unit - 2 Prepared By Page 27 Mr. D. Sulthan Basha Lecturer in Computer Science Now we can define at least two tables for this ER diagram. 1. PERSON 2. ICE CREAM Name Address Phone No. Manufacturer Flavour Price 2.5 Advantages and Disadvantages of ER Model  Advantages: Following are the advantages of an ER Model 1. Conceptual Simplicity 2. Visual Representation 3. Effective Communication Tool 4. Integrated with Relational database Model. Conceptual Simplicity: ER Model represents the concepts of a database along with its entities and relationships in an easy way. It becomes even easier to create and manage the complex database designs by using ER Model. Visual Representation: ER Model provides a visual representation of data and the relationships among data. It helps the database designers, programmers and end users to understand the structure of data in an easy way. It also minimizes the data redundancy. Effective Communication Tool: The database designer can use ER Model to get different views of data. As seen by programmers, managers and end users etc. ER Model works as an effective communication tool to integrate the views. Integrated with relational database Model: ER Model is well integrated with the relational database Model. These integration makes relational database design a very structured process.  Disadvantages: Following are the disadvantages of an ER Model. 1. Popular for High-level design 2. No Industry Standard 3. Limited Relationship Representation Popular for high-level design: The ER Model is especially popular for high level database design. No Industry Standard: There is no Industry Standard notation for development an ER diagram. Development Relationship Representation: ER Model represents Limited relationships among the entities.
  • 32. Database Management System Unit - 2 Prepared By Page 28 Mr. D. Sulthan Basha Lecturer in Computer Science Unique attributes of subtypes 2.6 Enhanced Entity Relationship Model (or) Extended ER Model The ER Model has been introduced during 1970’s but the business environment has changed dramatically. Since that time business relationships are more complex, as a result the business data became more complex. So the researchers have continued enhancing of ER diagrams. So that they can more accurately represents the complex data in business environment. The term enhanced entity relationship Model is used to identify the Model that has resulted from extending the original ER Model with new model construct. The Most important new modeling constructs is sub type/super type relationship. This facility allows to model a general entity type called super type. And then sub divided into several entity types is called subtype. For example, the entity type employee can be modeled as a super type with the sub types REGULAR, CONTRACT, CAUSAL. Each sub type inherits attributes from its super types and in addition the sub types may have special attributes of its own. Super type and sub type Entities Super type: A General entity type that has a relationship with one or more subtypes is called super type. Sub type: A sub grouping of entities in an entity type that is meaningful to the organization and that shares common attributes or relationships from other sub groupings. A basic notation for representing sub type, super type relationship is SUPER TYPE Common attributes to share to the subtypes Sub types
  • 33. Database Management System Unit - 2 Prepared By Page 29 Mr. D. Sulthan Basha Lecturer in Computer Science Unique attributes of subtypes From the above notation the super type is connected with a line to a circle, which is connected by a line to each sub type that has been defined the “U” shaped symbol on each line connecting sub type to the circle indicate that the sub type is a subset of the super type. It also indicates the direction of the sub type, super type relationship. The attributes that are shared by all entities are associated with the super type. The attributes that are Unique to a particular sub type those are associated with that sub type. Example: 2.7 Explain Generalization and Specialization Generalization: Generalization is a process of defining more general entity type from a set of more specialized entity types. So generalization is called Bottom up process. Consider the following entities CAR, TRUCK and MOTOR CYCLE. EMPLOYEE ID Name DOB REGULAR CONTRACT CASUAL Sal Exp Period Wage Common attributes to share to the subtypes Sub types Amt CAR ID Model Make Price No.of Passengers TRUCK ID Model Make Price Load Capacity Cabin Type
  • 34. Database Management System Unit - 2 Prepared By Page 30 Mr. D. Sulthan Basha Lecturer in Computer Science The generalization allows us to group entity types with common attributes, at the same time the generalization pressure us to specify the specific attributes to their entity types. From the above example we have defined a general entity called VEHICLE with common attributes. The specialized attributes are defined with their sub type entity set. Specialization: Specialization is process of defining one or more subtype of the super type and forming super type sub type relationship. Each sub type is formed based on some specialized properties consider the following ER diagram. VEHICLE ID Model Price CAR TRUCK MOTOR CYCLE No.of Passengers Cabin type No.of Gears Load capacity Make MOTOR CYCLE ID Model Make Price No.of Gears From these ER diagrams we are having three entity types called CAR, TRUCK, and MOTOR CYCLE. At this stage that data modular intends represent these entities separately. By examining closely, we can see that the entity types are having the common attributes; they are Id, Model, Make, and Price. This fact suggests that each of the three entity types belongs to a version of more general entity type.
  • 35. Database Management System Unit - 2 Prepared By Page 31 Mr. D. Sulthan Basha Lecturer in Computer Science ISA By applying specialization in the above concept we will get two sub type entity types called manufactured part and purchased part. 2.8 ISA Relationship and Attribute Inheritance ISA Relationship supports attribute Inheritance and relationship participation in the EER diagram, the sub class relationship is represented by IS A relationship. Attribute inheritance is the property by which sub class entities inherit values for all attributes of the super class. For example take a group “person”. A person has name, d.o.b, Gender, etc. These properties are common in all persons, human beings but in a company, persons can be identified as employee, employees, customers, vendor based on what role they play in the company similarly in a college database or a staff based on what role they play in college as entities. PART P.Name Supplier Cost Weight MF_Date P.No From this ER diagram the entity type PART is having several attributes. They are pin Number, Name, Supplier, Weight, manufactured date and cost. While discussing with users the developers discovered that they are two possible sources for PARTS. Some parts are manufactured internally; others are purchased from outside vendors. PART P.Name Supplier Cost Weight MF_Date P.No MANUFACTURED PART PURCHASED PART PERSON STUDENT TEACHER It is to be observed that the student and the teacher inherit some of the attributes of the person.
  • 36. Database Management System Unit - 2 Prepared By Page 32 Mr. D. Sulthan Basha Lecturer in Computer Science 2.9 Aggregation Aggregation is a process when relation between two entities is treated as a single entity foe example. The relation between “CENTER’’, “course” entities is acting as a single entity in relation with the entity “VISITOR”. 2.10 Multiple Inheritance A sub class with than one super class is called a shared sub class. A subclass inherits attributes not only of its direct super class, but also of all its predecessor super class, that is it has multiple inheritance a sub class can be sub class of more than one super class. For example, consider a person in an educational Institution the person can be employee, alumnus, and student. The employee entity can be staff or faculty. The student can be a graduate or post graduate student. The post graduate student can be a teaching assistant if the post graduate student is a teaching assistant, then he/she inherits the characteristic of the faculty as well as student class. That is the teaching assistant sub class is a sub class of more than one super class. This phenomenon is called multiple inheritance and is shown in below diagram. CENTER COURSE Offer VISITOR Enquire PERSON EMPLOYEE STUDENT UNDER GRADUATE STAFF FACULTY POST GRADUATE CLASS TEACHING ASST Teach Assist
  • 37. Database Management System Unit - 2 Prepared By Page 33 Mr. D. Sulthan Basha Lecturer in Computer Science 2.11 Constraints on Specialization and Generalization The Constrains on Specialization and Generalization can be classified into 1. Disjointness Constraint 2. Completeness Constraint Disjointness Constraint: The Disjointness constraint allows us to specify the whether an instance of a super type may simultaneously be a member of two or more subtypes. In disjointness, we have two categories. (a) Overlap Constraint (b) Disjoint Constraint Overlap Constraint: Overlap refers to the fact that the same entity instance may be a member of more than one subclass of the specialization. Example: Consider the example of “ANIMAL” Entity, which can be further subdivided into ‘LAND ANIMAL’ and ‘WATER ANIMAL’. Consider the example of frog and crocodile which can live both land and water. Hence the division of animal into land and water animals is an example of overlap constraints. Disjoint Constraint: Disjoint refers to the fact that the same entity instance may be a member of only subclass of the specialization. Example: Consider the example of “CATA LOGUE”. The catalogue is a super class which can be further subdivided into ‘Books’, ‘JOURNALS’, and ‘PERIODIALS’. This false under disjointness because a book entity can be neither “JOURNAL” NOR “PERIODICAL”. ANIMAL LAND ANIMAL WATER ANIMAL O CATALOGUE BOOK PERIODICAL d JOURNAL
  • 38. Database Management System Unit - 2 Prepared By Page 34 Mr. D. Sulthan Basha Lecturer in Computer Science Completeness Constraint: The completeness constraint addresses the question whether an instance of a super type must also be a member of at least one sub type. In completeness, we have two categories. (a) Total Specialization (b) Partial Specialization Total Specialization: Total completeness refers to the fact that every entity instance in the super class must be a member of some sub classes in the specialization. With total specialization, am instance of the super type must be a member of at least one sub type. Example: Consider the example of ‘TEACHER’. The teacher is a general term, which can be further specialized into ‘LECTURER’, ‘TUTOR’ and ‘DEMONSTRATOR’. Here every member in the super class participates as a member of a sub class; hence it is an example of total participation. Partial specialization: Partial Completeness refers to the fact an entity instance in the super class need not be a member of any sub class in the specialization. With partial specialization an instance of a super type may subtype. Example: Consider ‘PERSON’ specialization into ‘EMPLOYEE’ and ‘STUDENT’. This is an example of partial specialization because they can be a person who is unemployed and doesn’t study. TEACHER LECTURER DEMONSTRATOR d TUTOR Name ID Salary Hours worked Double line represents total Participation ‘d’ represents disjointness PERSON EMPLOYEE STUDENT O Single line represents partial Participation ‘O’ represents Overlap Name ID
  • 39. Database Management System Unit - 2 Prepared By Page 35 Mr. D. Sulthan Basha Lecturer in Computer Science 2.12 Entity Clusters EER diagrams are difficult to read when they are many entities and relationship. One possible solution is to group entities and relationships into entity clusters. Entity cluster is a set of one or more entity types and associated relationships grouped into a single abstract entity type. Entity cluster behaves like an entity types can be further grouped to form a higher level entity cluster. To understand entity cluster, consider the example of Hospital Management. In Hospital, the ‘DOCTOR’ treats the “PATIENT”. The doctors are payed the ‘management’ which builds buildings or specialist like those with MS OR MD. The patient can be either inpatient or outpatient. It is to be noted that only outpatient will be allotted bed. If we have to represent these ideas, it can be done using EER diagrams as shown in below diagrams. The above diagram is found to be complex; the same idea is represented using entity clusters as shown in below diagram. MANAGEMENT BUILDINGS builds appoints DOCTOR treats PATIENT No.of rooms GENERAL PHYSICIAN SPECIALIST IN-PATIENT OUT-PATIENT Specialization Patient ID is assigned to BED Bed No. MANAGEMENT DOCTOR HOSPITAL PATIENT employs manage treats In the above diagram entities as well as relationships are clustered into simply entity set.
  • 40. Database Management System Unit - 3 Prepared By Page 36 Mr. D. Sulthan Basha Lecturer in Computer Science UNIT-3 Relational Model Introduction: The Relational data Model is the conceptual bases of relational data bases proposed by Dr. EF CODD in 1970. The Relational Model is considered as one of the most popular development in the database technology because it can be used for representing most of the real world objects and the relationship between them. The main construct for representing data in the relational model is a relation, where each relation is a table with rows and columns. Relational database established a well defined relationship between database tables. A well designed relational database should eliminate data redundancy i.e. the same piece of data should not be store in more than one place. This is because duplicate data not only waste storage spaces but also easily lead to inconsistency. It should also ensure data integrity and accuracy. 3.1 Basic Concepts of Relational Model The relational data model uses formal terms like attributes, Tuple, Relation, domain, schema and keys to define its concepts. Let us define each of these terms Attribute:An attribute can be defined as a characteristic of data. A real world data feature modeled in the database will be represented by an attribute. Relation: A Domain describes the set of possible values that are all of the same type for a given attribute. A value is the smallest unit of data in the relational model. Domain: A Database schema is a formal description of all the database relations and all the relationships existing between them. Key: The Relation data model uses keys to define identifiers for a relation’s Tuples. A key is an attribute of a table which helps to uniquely identify s row. 3.2 CODD Rules In 1985, Dr. EF CODD published database system. The reason Dr many, vendors were marking products as ‘relational’ even though those products did not meet minimum relational standards. Dr. E.F codd’s rules shown in below, that are reference for what a truly relational database should be I. Information II. Guaranteed Access III. Systematic treatment of Nulls IV. Dynamic on-line catalog Based on the Relational model. V. Comprehensive data sublanguage VI. View updating VII. High-level Insert, update and delete VIII. Physical data Independence
  • 41. Database Management System Unit - 3 Prepared By Page 37 Mr. D. Sulthan Basha Lecturer in Computer Science IX. Logical data Independence X. Integrity Independence XI. Distribution Independence XII. Non sub version Information: All Information in a relational database must be logically represented as column values in rows with in tables. Guaranteed Access: Every value in a table is guaranteed to accessible through a combination of table name, primary key value and column name. Systematic treatments of Nulls: Nulls must be represented and treated in a systematic way, independent of data type. Dynamic on line catalog based on the Relational Model: The Metadata must be stored and managed as ordinary data that is, in the tables within the database. Such data using the standard database relational languages. Comprehensive Data sublanguage: The Relational database may support many languages. However it must support one well defined, declaration language with support for data definition, view definition, data manipulation, integrity constraints, authorization, and transaction management. View Updating: Any view that is theoretically updatable must be updatable through the system. High-level Insert, update and delete: The database must support set-level inserts, updates, and deletes. Physical data Independent: Application programs and ad hoc facilities are logically unaffected when physical access methods or storage structures are changed. Logical data Independent: Application programs and ad hoc facilities are logically unaffected when changes are mades to the table structure preserve the original table values. Integrity Independence: All relational integrity constraints must be definable in the relational language and stored in the system catalog not at the application level. Distribution Independence: The end users and application programs are unaware and unaffected by the data location.
  • 42. Database Management System Unit - 3 Prepared By Page 38 Mr. D. Sulthan Basha Lecturer in Computer Science Non sub version: If the system supports low-level access to the data, there must not be a way to bypass the integrity rules of the database. Rule Zero: All preceding rules are based on the notation that in order for a database to be considered relational, it must use its relational facilities exclusive to manage the database. 3.3 Relational Integrity  One of the most important responsibilities of a database administrator (DBS) is to maintain the integrity of the database and prevent it from becoming corrupted.  Database integrity means the completeness, correctness and consistency of data. It ensures that data entered into the database must be complete, occurrence valid and consistent. It is another form of database protection.  In a Relational data model, data integrity or data accuracy can be achieved using integrity rules or constraints. An integrity constraints is a condition that is specified on a database schema, and characteristics and the data that can be stored in an instance of the database. Integrity constraints may be divided into three main categories (i) Domain Integrity (ii) Entity Integrity (iii) Referential Integrity Domain Integrity: Domain Integrity rules are associated with maintaining the correctness of validity of entries for a given column. We can enforce domain integrity by restricting the type (through data types). The format ( through CHECK constraints and rules ) or the range of possible values. Entity Integrity: Entity Integrity rules ensure that it should be easy to identify each entity in the database. The entity integrity is a constraints on primary key value. It states key that any attribute of a primary key cannot contain null value. If primary key contains null values. It is not possible to uniquely identity a record in a relation. Relational Integrity: Referential Integrity rules are concerned with maintain the correctness and consistency of relationships between relations. To define referential integrity constraints it is necessary to define the foreign key first. A foreign key is an attribute or a set of attributes within one relation that matches the primary key of some other relation. In relational databases, sometimes it requires to ensure that a value that appears in an relation for a given attributes (or a given set of attributes) also appears for a certain attribute (or a certain set of a attributes) in another relation. This is known as referential integrity constraints, which is expressed in terms of foreign keys.
  • 43. Database Management System Unit - 3 Prepared By Page 39 Mr. D. Sulthan Basha Lecturer in Computer Science 3.4 Relational Keys in DBMS A key is an attribute (also known as column/field or a combination of attributes that is used to identity records. Sometimes we may have to retrieve data from more than one table, in those cases we required to join tables with the help of keys. The purpose of the key is to bind data together across tables without repeating all of the data in every table. The following are the types of keys. i) Super key ii) Candidate key iii) Primary key iv) Secondary key v) Foreign key Super key: An attribute or a combination of attributes that are used to identify the records uniquely is known as super key. A table can have many super keys. Ex: Sno Sno, sname Eno, ename, address Candidate key: It can be defined as minimal super key. A super key that doesn’t contain a subset of attributes that is itself a super key. Ex: Sno, Sname etc Primary key: A candidate key that is used by the database designer for unique identification of each row in a table is known as primary key. Ex: sno Eno Prod_id Secondary key: An attribute or combination of attribute used strictly for data retrieval purpose is called secondary key. Ex: Sname, percentage ename, address. Foreign key: A foreign key is an attribute or combination of attributes in one table that points to the primary key of another table. The purpose of the foreign key is to ensure referential integrity of the data. Ex: Employee (emp-id, emp-name, emp-sal) Department ( Dept-id, Dept-name, emp-id) In the above example emp_id is the primary key for employee table and foreign key for department table.
  • 44. Database Management System Unit - 3 Prepared By Page 40 Mr. D. Sulthan Basha Lecturer in Computer Science 3.5 Null Values If table contains no values for any field is a records, then that field is called NULL value. If the column was created as NULLABLE, oracle will place a NULL value in the column in the absence of a user defined value. A NULL value is different from a blank or a zero. NULL values can be inserted into the columns of any data type. Principles of NULL values:  Setting a NULL value is it would not be meaningful.  A NULL value is not equivalent to a value of zero if the data type is number.  A NULL value is not equivalent to spaces if the data type is character.  A NULL value will evaluate to NULL in any expression, for example NULL multiplied by 10 is NULL.  NULL value can be inserted into columns of any data type.  If the column has a NULL value, then no constraints will work on that column. 3.6 Relational Algebra Every database management system must define a query language to allow users to access the data stored in the database. Relational Algebra is a procedural query language used to query the database tables to access data in different ways. In Relational algebra, input is a relation (table from which data has to be accessed) and output is also a relation ( a temporary table holding the data asked for by the use). Relational algebra works on the whole table at once, so we do not have to use loops etc to iterate overall the rows (tuples) of data one by one. All we have to do is specify the table name from which we need the data, and in a single line of Command, relational algebra will traverse the entire given table to fetch data for you. 3.6.1 Relational Algebra Operations The primary operations that we can perform using relational algebra are: 1. Select 2. Project 3. Union 4. Set Different 5. Cartesian Product 6. Rename Select Operations (σ): This is used to fetch rows (tuples) from table (relation) which satisfies a given condition. Syntax: σp(r) Where, σ represents the select predicate, r is the name of relation ( table name in which you want to look for data), and p is the prepositional logic, where we specify the conditions that must be satisfied by the data. In
  • 45. Database Management System Unit - 3 Prepared By Page 41 Mr. D. Sulthan Basha Lecturer in Computer Science prepositional logic, one can we unary and binary operators like =, <, > etc, to specify the conditions. Lets take an example of the ‘student’ table we specify above in the introduction of relational algebra, and fetch data for students with age more than 17. σage>17(STUDENT) This will fetch the tuples (rows) from ‘student’, for which ‘age’ will be greater than 17. You can also use, and pr etc operators, to specify two conditions, for example σage>17 AND gender=’Male’(STUDENT) This will return tuples (rows) from table student with information of male students, of age more than 17. Project Operation(π): Project Operation is used to project only a certain set of attributes of a relation. In simple words, if you want to see only the ‘names’ all of the students in the ‘student’ table, then you can use project operations. It will only project or show the columns or attributes asked foe, and will also remove duplicate data from the column. Syntax: πA1,A2(R) Where A1, A2 etc are names of attributes (column names) for example, πName, Age (STUDENT) Above statement will show as only the ‘Name’ and ‘age’ columns for all the rows of data in ‘Student’ table. Union Operation(U): This Operation is used to fetch data from two relations (tuples) or temporary relation (result of another operation) For this operation to work, the relations (tuples) specified should have same number of attributes (columns) and same attribute domain. Also the duplicate tuples are automatically eliminated from the result. Where A and B are relations. For Example, if we have two tuples ‘Regular class’ and ‘extra class’, both have a column student to save name of student, then, πstudent (REGULAR CLASS) U πstudent(EXTRA CLASS) Above operation will give us name of ‘students’ who are attending both regular classes and extra classes, eliminating repetition.
  • 46. Database Management System Unit - 3 Prepared By Page 42 Mr. D. Sulthan Basha Lecturer in Computer Science Set Difference(-): This operation is used to find data present in one relation and not present in the second Relation, this operation is also application on two relations, just like Union Operation. Syntax: A-B Where A & B are relations. For Example, if we want to find name of students who attend the regular class but not the extra class, then, we can use the below Operation: πStudent(REGULAR CLASS)-πStudent(EXTRA CLASS) Cartesian Product(X): This is used to combine data from two different relations (tuples) into one and fetch data from the combined relation. Syntax: A*B For example, if we want to find the information for REGULAR CLASS and EXTRACLASS which are conducted during morning, then, we can use the following operations. σtime=’Morning’(REGULAR CLASS X EXTRA CLASS) Rename Operation (p) This operation is used to rename the output relation for any query operation which returns result like select, project etc, or to simply rename a relation (table) Syntax: p(Relation New, Relation old) 3.6.2 Relational calculus (TRC) Contrary to Relational algebra which is a procedural query language to fetch data and which also explains how it is done, ‘Relational Calculus’ is non-procedural query language and has no description about how the query will work or the data will be fetched. It only focuses on what to do, and not on how to do it. Relational calculus exits in two forms: 1. Tuple Relational calculus 2. Domain Relational calculus Tuple Relational Calculus: In tuple relational calculus, we work on filtering tuples based on the given condition. Syntax: { T | condition } In this form of relational calculus, we define a tuple Variable, specify the table (relation) name in which the tuple is to be Searched for, along with a condition. We can also specify column name using a dot operation, with the tuple variable to only get a certain attributes (column) in result.
  • 47. Database Management System Unit - 3 Prepared By Page 43 Mr. D. Sulthan Basha Lecturer in Computer Science A lot of information, right! Given it some time to sink in a tuple variable is nothing but a name, can be anything, generally we use a single alphabet for this, so lets say T is a tuple variable. To specify the name of the relation (table) in which we want to look for data, we do following Relation (T), where T is out tuple variable. For example if our table is ‘student’ we would put it as a student (T) Then comes the condition part, to specify a condition applicable for a particular attribute (column), we can use the . dot variable with the tuple variable to specify it, like in table ‘student’, if we want to get data for students with age greater than 17, then we can write it as: T-age>17 Where T is our tuple variable putting it all together, if we want to use tuple relational calculus to fetch names of students, from table ‘Student’ with age greater than 17, then, for T being our tuple variable. T.name/student (T) AND T. age>17 Domain Relational calculus (DRC): In domain relational calculus, filtering is done based on the domain of the attributes and not based on the tuple values. Syntax:- { C1 C2, C3,………Cn /F(C1,C2, C3,…….C } Where C1, C2, …..etc represents domain of attributes (column) and F defines the formula including the condition for fetching data. For example, {<name, age/student ^ age>17} Again, the above query will return the names and ages of the students in the table ‘student’ who are older than 17. 3.6.3 Advantages of Relational Algebra  The Relational algebra has solid mathematical background. The mathematical background of relational algebra is the basis of many interesting developments and theorems. If we have two expressions for the same operation and if the expressions are proved to be equivalent, then a query optimizer can automatically substitute the more efficient form.  Relational algebra is a high level language which talks in terms of properties of sets of tuples and not in terms of for-loops. 3.6.4 Limitations of Relational Algebra  The Relational algebra cannot do arithmetic. For example, if we want to know the price of 10l of petrol, by assuming a 10%. Increase in the price of the petrol, which cannot be done using relational algebra.  The Relational algebra cannot sort or print results in various formats. For example, if we want to arrange the product name in the increasing order of their price. It cannot be done using relational algebra.
  • 48. Database Management System Unit - 3 Prepared By Page 44 Mr. D. Sulthan Basha Lecturer in Computer Science  Relational algebra cannot perform aggregates. For example, if we want to know how many staff members are working in a particular department. This query cannot be performed using relational algebra.  The Relational algebra cannot modify the database. For example, if we want to increase the salary of all employees by 10%. This cannot be done using relational algebra. 3.7 QBE: QBE stands for “Query By Example”. In database of management systems, QBE refers to a method of forming queries in which the database program displays a blank record with a space for each field. You can then enter conditions for each field that you want to be included in the query for example, if you want to find all records where the AGE field is greater than 65, you would enter >65 in the AGE field blank. QBE uses a terminal display with attributes names as table headings for queries. It is very easy to list the entire schema, simply by scrolling information on the screen. QBE was developed originally by IBM in the 1970S to help users in their retrieval of data from a database. QBE represents a visual approach for accessing data in a database through the use of query templates. QBE can be considered as GUI (Graphical user interface) based on domain calculus. QBE allows users to key in their input requests by filling in empty tables on the screen, and the system will also display its response in tabular form. QBE is user-friendly because the users are not required to formulate sentences for query requests with rigid query-language syntax. In QBE the request is entered in the form of tables whose skeletons are initially constructed by QBE. QBE is easier to learn than formal query languages, such as the standard structured query language (SQL).
  • 49. Database Management System Unit - 4 Prepared By Page 45 Mr. D. Sulthan Basha Lecturer in Computer Science UNIT-4 STRUCTURED QUERY LANGUAGE (SQL) Introduction: SQL is the standard language used to communicate with the database system. Without SQL we cannot able to do any operation on the database. So SQL is called “Heart of DBMS”.All the tasks related to dbms are performed though SQL i.e,creating tables,modifying rows,deleting rows etc. The name SQL pronounced as “ESS-CUE-ELL” or “SEQUEL”. The SQL language was developed at SAN JOSE RESEARCH laboratory at IBM.IBM was implemented the language called “SEQUEL” in the year 1970 and its name had been changed to SQL. SQL is a high level language that provides a greater degree of abstraction than procedural languages. All the communications to DBMS must be performed through SQL.The SQL having four types of statements ,they are: 1.Data Definition Language(DDL) 2.Data Manipulation Language(DML) 3.Data Retrieval Language(DRL) 4.Data Control Language(DCL) 5.Transcation Control Language(TCL) DDL: By using DDL statements a user can create a table structure, modify & delete the structure. DDL contains the following commands. CREATE,ALTER ,DROP & RENAME DML: By using DML statements the user can able to insert, update, & delete the records in a table . DML contains the following commands. INSERT, UPDATE, &DELETE, TRUNCATE DRL: By using DRL statements the user can able to extracts the stored information from the database table . DRL contains the following commands only. SELECT DCL: By using DCL statements the database administrator can grant permissions on the database and tables. In some cases the granted permissions can be revoked. DCL contains the following commands. GRANT & REVOKE TCL: By using TCL statements the user can able to store records permanently and retrieve ,restore the records which are deleted mistakenly. TCL contains the following commands. COMMIT, ROLLBACK, & SAVEPOINT
  • 50. Database Management System Unit - 4 Prepared By Page 46 Mr. D. Sulthan Basha Lecturer in Computer Science 4.1 DATA TYPES While defining the columns, the user has to specify its datatype and its size. The SQL supports the following datatypes Char(n) Number(n) Number(n,d) Varchar(n) Varchar2(n) DATE,LONG,RAWL LONG RAW CHAR(N): By using this datatype we can able to store character type of data. We can store a maximum of 255 characters. NUMBER(N): By using this datatype we can able to store a 40 digited integer number. NUMBER(N,D): By using this datatype we can able to store a 40 digited read value. Here ‘n’ defines the total number of digits including decimals,’d’ defines the decimal points in the number. DATE: By using this datatype, we can able to store date and time. VARCHAR/VARCHAR2(N): By using this datatype we can able to store variable length upto 2000 characters. LONG(N): By using this datatype we can able to store a variable length string of 2GB. RAW/LONGRAW(N): The RAW&LONGRAW are used to store binary data upto 240 bytes and 6535 bytes respectively. 4.2 PERFOMING SQL COMMANDS 4.2.1 Create Table Statement: This statements is used to create a structure of database table. Syntax:- CREATE TABLE <Table_name>( Col_name1 Datatype(size), Col_name2 Datatype(size), . . . Col_nameN Datatype(size); From the above syntax a database table is created with defined columns.A table may have a maximum of 254 columns. While defining the names of table and columns,the user has to follow the below conditions.
  • 51. Database Management System Unit - 4 Prepared By Page 47 Mr. D. Sulthan Basha Lecturer in Computer Science  The column name or table name must be started with an alphabet.  No special characters are allowed in between the column names and table names except underscore(_) and dollar symbol($).  The reserved words are not allowed for defining as names for column & table. EXAMPLES OF TABLE CREATION: CREATE TABLE STUDENT( S.no Number(3), Name Varchar2(15), Class Char(6), Age Number(2), Fee Number(7,12)); 4.2.2 INSERT STATEMENT : The “Insert Statement” is used to insert rows into a table. Syntax: Insert INTO<Table_name>Values (col-1,col-2,col-3…….); Example: Insert into student values(1907,’ Afiya’,’BSC’,’19’,12000); From the above syntax and examples we can insert total values in a row, while defining the values, the non-numeric constants such as characters and strings has to be enclosed under (b/w) single coats(‘ ‘); INSERTING ROWS BY SPECIFYING THE COLUMN NAMES: SYNTAX:- Insert into table name(col_name1,col_name2…….,col_name-n) Values(col-1 value,col-2 value……); Example:- Insert into student (sno,Name,Age) Values(1907,’Afiya’,19); INSERTING ROWS BY USING “&” IN INSERT STATEMENT: Syntax:- Insert into table_name values(&col_name1,&col_name2……..); Example: Insert into student values(&sno,’&name’,’&class’,&age,&fee); Enter value for sno:1907 Enter value for Name: Afiya Enter value for class: BSC Enter value for AGE:19 Enter value for Fee: 12000 (enter) /(press slash & Enter key) 4.2.3 DISPLAYING ROWS WITH SELECT STATEMENT The SELECT statement is used to display the rows and columns values on the screen Syntax:- SELECT * from <table_name>; Examples: SELECT * from STUDENT;
  • 52. Database Management System Unit - 4 Prepared By Page 48 Mr. D. Sulthan Basha Lecturer in Computer Science Q: Write an SQL statement to create a table for Employee and it contains the columns as Eno,Ename,Basic_sal,and address. And insert 5 rows into the employee table . CREATE TABLE EMPLOYEE( Eno number(4), Ename varchar2(10), Basic_sal number(7,2), Address char(8) ); Insert into employee values(1501,’sonu’,10000,’gtl’); Insert into employee values(1502,’neha’,10500,’atp’); Insert into employee values(1503,’rahul’,10820,’knl’); Insert into employee values(1504,’javeed’,40000,’gtl’); Insert into employee values(1505,’sabiha’,50000,’gtl’); 4.2.4 DESCRIBING A TABLE The DESCRIBE statement is used to view the table definitions on the screen. Syntax 1: DESC <TABLE_NAME> Synatx 2: DESCRIBE<TABLE_NAME> Example: DESCRIBE EMPLOYEE 4.2.5 SPECIFYING A “DEFAULT VALUE “ FOR A COLUMN:- By using “ default “ clause, we can supply a default value for a column. This default value is supplied whenever a row is inserted without column values in the insert statement. The “default” clause is used (or) defined in CREATE/ALTER Statement. Syntax: <col_name Datatype(size) DEFAULT Value> Example: CREATE TABLE EMPLOYEE( ENO NUMBER(4), ENAME VARCHAR2(10),BSAL NUMBER (7,12), TA NUMBER(4), DEFAULT 2000, DA NUMBER(4),DEFAULT 1000, HRA NUMBER(4),DEFAULT 1500); 4.2.6 SELECTING SPECIFIED ROWS FROM A TABLE By using the “SELECT” statement and “WHERE” clause,we can able to select the specified number of rows from a table. Syntax: SELECT * FROM <TABLE_NAME> WHERE < CONDITION>; Example: SELECT * FROM STUDENT WHERE GROUP=’BSC’;
  • 53. Database Management System Unit - 4 Prepared By Page 49 Mr. D. Sulthan Basha Lecturer in Computer Science 4.2.7 SELECTING SPECIFIED COLUMNS FROM A TABLE By using “SELECT” Statement, we can able to select the specified number of columns from table. Syntax: SELECT col-1,col-2,col-3,…….from <Table_name>; Example: SELECT sno,sname from STUDENT; 4.2.8 EXPRESSIONS IN SELECT STATEMENT By using the expression in SELECT statement we can able to create virtual columns Syntax:- SELECT col-1,col-2,…..exp1,exp2…….. FROM<TABLE_NAME> WHERE < CONDITION>; Example: SELECT Sno,Sname,Sub1+Sub2+Sub3, (Sub1+Sub2+Sub3)/3 From STUDENT WHERE Sno=1506; 4.2.9 ORDERING ROWS BY USING “ORDER BY” CLAUSE The “ORDER BY” clause is used to extract the rows in an order i.e either in ascending order/descending order.The ORDER BY clause should be defined with the “SELECT” statement. Syntax:- SELECT columns from <Table_name> ORDER By col_name[ASCE/DESE] WHERE <condition>; Example: SELECT * from student ORDER BY sname DESC WHERE Group=’BSC’; NOTE: In select statement ‘*’ is used for retrieving all the columns values of tables. 4.2.10 SUBSTITUTING VARIABLES To take the input from a user,we can substitute variables in WHERE Clause. To substitute variables we have to use to “&” symbol before variable. Example: SELECT * from employee WHERE Ename = ‘&Ename’; From the above examples before executing the SELECT statement it prompts for the user input. After giving the input the value is substituted with ‘&Ename’ and executes the statement. 4.2.11 DELETE Statement The DELETE statement is used to remove the rows from a table. Syntax: DELETE from <Table_name>; From the above syntax the DELETE statement deletes all rows from the table In order to delete specified rows ,the following syntax can be used.
  • 54. Database Management System Unit - 4 Prepared By Page 50 Mr. D. Sulthan Basha Lecturer in Computer Science Syntax: DELETE from <Table_name> WHERE <condition>; Example: DELETE from student WHERE sno=1502; 4.2.12 TRUNCATE Statement: The TRUNCATE statement is used to delete all rows permanently in a table. Syntax: TRUNCATE Table<Table_name>; Example: TRUNCATE TABLE Student; 4.2.13 ALTER TABLE Statement The alter table statement is used to change the structure of existing table by adding new columns & increasing the column width(or) changing the datatype of a column etc. The ALTER TABLE uses two keywords. They are : 1. ADD 2. MODIFY  The keyword “ADD” is used to add new columns to the table.  The keyword “MODIFY” is used to change the datatype(or) size of an existing column. Syntax1: ALTER TABLE<Table_name> ADD(col-1 datatype,col-2 datytype,….); Syntax2: ALTER TABLE <Table_name> MODIFY(Existing_col_name Datatype to be changed); Example: 1) ALTER TABLE Student ADD(Total_marks number(3)); 2) ALTER TABLE Student MODIFY (Sname varchar2(30)); 4.2.14 RENAME TABLE Statement The RENAME TABLE Statement is used to change the name of the existing table Syntax: RENAME <old_table_name> To <new_table_name>; Example: RENAME Student to std; 4.2.15 DROP TABLE statement This statement is used to delete on existing table permanently from database. Syntax: DROPTABLE <Table_name>; Example: DROP TABLE Student; 4.2.16 UPDATE statement: The “UPDATE” statement is used to change the existing information Of a row (or) multiple rows of a table. Syntax: UPDATE <Table_name> SET Expression WHERE<condition>;
  • 55. Database Management System Unit - 4 Prepared By Page 51 Mr. D. Sulthan Basha Lecturer in Computer Science Example: UPDATE Student SET Total_marks=sub1+sub2+sub3 WHERE Group=’BSC’; NOTE: “SET” clause is used to define the attribute or column and the expression are changes to occur in the relative rows. 4.3 LOGICAL OPERATORS There are three logical operators in SQL that can be used in SQL sentences. 1. AND Operator 2. OR Operator 3. NOT Operator AND opeartor: The oracle engine will process all rows in a table and display the result only when all of the conditions specified using the AND operator are satisfied. Example1: SELECT * from product WHERE profit-percent>=10 AND profit-percent<=20; Example2: SELECT * FROM STUDENT WHERE AVG>=75 AND AVG<=90; OR operator: The oracle engine will process all rows in a table and display the result only when any of the conditions specified using the OR operator are satisfied. Example: SELECT * from Employee WHERE address =”GTL” OR ADDRESS=ATP; NOT operator: The oracle engine will process all rows on a table and display the result only when none of the conditions specified using the NOT operator are satisfied. Example1: SELECT * FROM EMPLOYEE WHERE NOT(B-SAL=2000 (or) B-SAL=3000); Example2: SELECT * FROM STUDENT WHERE NOT MARKS=250; 4.4 BETWEEN,IN& LIKE OPERATOR BETWEEN operator: The BETWEEN operator is used to select rows that contains the values with in a specified range. Syntax: SELECT col_s from <table_name> WHERE col BETWEEN lower_lmt AND Upper_lmt; Example: SELECT * FROM STUDENT WHERE avg BETWEEN 50 AND 60;
  • 56. Database Management System Unit - 4 Prepared By Page 52 Mr. D. Sulthan Basha Lecturer in Computer Science IN Operator: The “IN” Operator used to slect rows that matches one of the values in a list. Syntax: SELECT Col from <table_name> WHERE col IN (List of values separated by commas); Example: SELECT * FROM STUDENT WHERE SNO IN (1501,1502,1503); LIKE Operators: The “LIKE” operator is used to select the rows that partially match a portion of character. The LIKE operator uses two special characters to define the expression that is “%” and “-“.The LIKE operator is used only with “characters” and “varchar2” datatypes.The special character % defines one or more character.The special character “-“ specifies a single character. Syntax: SELECT cols from <table-Name> WHERE col like expression; Ex: Select * from student WHERE sname LIKE ‘A%’; 4.5 THE ORACLE TABLE DUAL DUAL is a small oracle work table,which consists of only one row and column,and contains the value ‘x’ in that column.Besides arithmetic calculations,it also supports data retrieval and its formatting. When an arithmetic exercise is to be performed such as 2*2 or 4/2 etc,there really is no table being referenced only numeric literals are being used. To facilitate such calculations via a SELECT,Oracle provides a dummy table called DUAL,against which SELECT statement that are required to manipulate numeric literals can be fired,and output obtained. Example: SELECT 2*2 from DUAL; Output: 𝟐∗𝟐 𝟒  The current date can be obtained from the table DUAL in the required format as shown below. SYSDATE: SYSDATE is a pseudo column that contains the current date and time. It requires no arguments when selected from the table DUAL & returns the current date. Example: SELECT sysdate from DUAL; Output: SYSDATE _ 25-Oct-2019