Complete Dbms Notes PDF
Complete Dbms Notes PDF
com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
1 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
3 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
5 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
the conceptual level.(describes
user/application View Level)
data
as
seen
by
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
6 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
7 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 02
Entity Relation Model:
The Entity Relationship (ER) data model allows us to
describe the data involved in a real world enterprise in terms
of objects and their relationships and is widely used to
develop an initial data base design. Within the larger context
of the overall design process, the ER model is used in a phase
called Conceptual database design.
Database design and ER Diagrams:
The database design process can be divided into six steps. The
ER model is most relevant to the first three steps.
1. Requirement Analysis:
The very first step in designing a database application
is to understand what data is to be stored in the database,
what application must be built in top of it, and what
operations are most frequent and subject to performance
requirements. In other words, we must find out what the users
want from the database.
2. Conceptual database Design:
The information gathered in the requirements analysis
step is used to develop a high-level description of the data
to be stored in the database, along with the constraints known
to hold over this data. The ER model is one of several highlevel or semantic, data models used in database design.
3. Logical Database Design:
We must choose a database to convert the conceptual
database design into a database schema in the data model of
the chosen DBMS. Normally we will consider the Relational DBMS
and therefore, the task in the logical design step is to
convert an ER schema into a relational database schema.
Beyond ER Design
4. Schema Refinement:
This step is to analyze the collection of relations in
our relational database schema to identify potential problems,
and refine it.
5. Physical Database
This step may
table and clustering
redesign of parts of
steps.
Design:
simply involve building indexes on some
some tables or it may involve substantial
database schema obtained from the earlier
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
8 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
9 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Types of Attributes:
Simple (Atomic) Vs. Composite
Single Valued Vs. Multi Valued
Stored Vs. Derived
Null Values
Simple Vs. Composite Attribute:
Simple
Attribute that are not divisible are called simple
or atomic attribute.
For example, Street_name or Door_number. i.e. the
division of composite attribute.
Composite
The attribute may be composed of several components.
For example, Address (Apt#, House#, Street, City,
State,
ZipCode,
Country)
or
Name
(FirstName,
MiddleName, LastName). Composition may form a hierarchy
where some components are themselves composite.
Single Valued Vs. Multi Valued:
Single Valued
An attribute having only one value.
For example, Age, Date of birth, Sex, SSN
Multi-valued
An entity may have multiple values for that
attribute.
For example, Color of a CAR or Previous Degrees of a
STUDENT. Denoted as {Color} or {PreviousDegrees}.Phone
number of an employee.
Stored Vs. Derived
In some cases two are more attributes values are related
for example the age and date of birth of a person. For a
particular person entity, the value of age can be determined
from the current (todays) date and the value of that persons
Birthdate.
The Age attribute is hence called a derived attribute and
is said to be derivable from the Birthdate attribute , which
is called stored attribute.
Null Values
In some cases a particular entity may not have an
applicable value for an attribute. For example, a college
degree attribute applies only to persons with college degrees.
For such situation, a special value called null is created.
Key attributes of an Entity Type:
An important constraint on the entities of an entity type
is the Key or uniqueness constraint on attributes. An entity
www.jntuworld.com
type usually has an attribute
whose values are distinct for
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
10 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Degree of a Relationship:
The
degree
of
a
relationship
is
the
number
of
participating
entity
types.
Hence
the
above
work_for
relationship is of degree two. A relationship type of degree
two is called Binary, and one of degree three is called
Ternary. An example of Ternary relationship is given below.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
11 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Relationship of degree:
o two is binary
o three is ternary
o four is quaternary
Another Example for Binary Relationship
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
12 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
13 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
ER Diagram
Notations for ER Diagram
Company
Schema
with
structural
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
16 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Identifying Relationship:
It is a relationship
entity.
between
Strong
entity
and
weak
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
17 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
additional
meaningful
sub
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
18 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Specialization:
Is the process of defining a set of subclasses of a super
class. The set of subclasses is based upon some distinguishing
characteristics of the entities in the super class
For Example,
{SECRETARY, ENGINEER, TECHNICIAN}
is a specialization of EMPLOYEE based upon job type.
Another specialization of EMPLOYEE based on the method of pay
is,
{SALARIED_EMPLOYEE, HOURLY_EMPLOYEE}.
Super class/subclass relationships and specialization can be
diagrammatically represented in EER diagrams. Attributes of a
subclass are called specific attributes.
For example, Typing Speed of SECRETARY
The subclass can participate in specific relationship types.
For example, BELONGS_TO of HOURLY_EMPLOYEE
Figure shows the Specialization of an Employee based on Job
Type.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
19 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Generalization:
FIGURE Generalization.
(a) Two entity types, CAR and TRUCK.
(b) Generalizing CAR and TRUCK into the superclass VEHICLE.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
20 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Attribute is called
specialization
3. User Defined
the
defining
attribute
of
defining attribute of
TECHNICIAN,
ENGINEER}
the
the
of
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
21 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
the
constraints
on
Specialization
&
4. Disjointness Constraint:
5. Completeness Constraint:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
22 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Specialization / Generalization
Shared Subclasses:
of
specialization
Hierarchies,
Lattices
and
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
23 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
A
specialization
ENGINEERING_MANAGER
lattice
with
shared
subclass
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
24 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 03
Relational Model
Relational Model Terminology :
A relation is a table with columns and rows.
Only applies to logical structure of the database,
not the physical structure.
Attribute is a named column of a relation.
Domain is the set of allowable values for one or more
attributes.
Tuple is a row of a relation.
Degree is the number of attributes in a relation.
Cardinality is the number of tuples in a relation.
Relational Database is a collection
relations with distinct relation names.
of
normalized
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
25 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
26 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
(1,4,6),
Properties of Relations
Relation name is distinct from all other relation names
in relational schema.
Each cell of relation contains exactly one atomic
(single) value.
Each attribute has a distinct name.
Values of an attribute are all from the same domain.
Each tuple is distinct; there are no duplicate tuples.
Order of attributes has no significance.
Order of tuples has no significance, theoretically.
Relational Keys
Superkey
An attribute, or a set of attributes, that uniquely
identifies a tuple within a relation.
Candidate Key
Superkey (K) such that no
superkey within the relation.
www.jntuworld.com
proper
subset
is
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
27 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Primary Key
Candidate key selected to identify tuples uniquely
within relation.
Alternate Keys
Candidate keys that are not selected to be primary
key.
Foreign Key
Attribute, or set of attributes, within one relation
that matches candidate key of some (possibly same)
relation.
Relational Integrity
Null
Represents value for an attribute that is currently
unknown or not applicable for tuple.
Deals with incomplete or exceptional data.
Represents the absence of a value and is not the
same as zero or spaces, which are values.
Entity Integrity
In a base relation, no attribute of a primary key
can be null.
Referential Integrity
If foreign key exists in a relation, either foreign
key value must match a candidate key value of some
tuple in its home relation or foreign key value must
be wholly null.
Enterprise Constraints
Additional rules
administrators.
specified
by
users
or
database
Views
Base Relation
Named relation corresponding to an entity in
conceptual schema, whose tuples are physically
stored in database.
View
Dynamic result of one or more relational operations
operating on base relations to produce another
relation.
A virtual relation that does not necessarily actually
exist in the database but is produced upon request, at
time of request.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
28 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Updating Views
All updates to a base relation should be immediately
reflected in all views that reference that base relation.
If view is updated, underlying base relation should
reflect change.
There are restrictions on types of modifications that can
be made through views:
Updates are allowed if query involves a single base
relation and contains a candidate key of base
relation.
Updates are not allowed involving multiple base
relations.
Updates are not allowed involving aggregation or
grouping operations.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
29 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 05
Query Languages: Relational Algebra :
Introduction
Relational algebra and relational calculus are formal
languages associated with the relational model.
Informally,
relational
algebra
is
a
(high-level)
procedural language and relational calculus a nonprocedural language.
However, formally both are equivalent to one another.
A language that produces a relation that can be derived
using relational calculus is relationally complete.
Relational Algebra
Relational algebra operations work on one or more
relations to define another relation without changing the
original relations.
Both operands and results are relations, so output from
one operation can become input to another operation.
Allows expressions to be nested, just as in arithmetic.
This property is called closure.
Five basic operations in relational algebra: Selection,
Projection,
Cartesian
product,
Union,
and
Set
Difference.
These perform most of the data retrieval operations
needed.
Also have Join, Intersection, and Division operations,
which can be expressed in terms of 5 basic operations.
Relational Algebra Operations
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
30 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
(R)
Works on a single relation R and defines a relation
that contains only those tuples (rows) of R that
satisfy the specified condition (predicate).
predicate
Projection
col1, . . . , coln(R)
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
31 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Example - Projection
Produce a list of salaries for all staff, showing only
staffNo, fName, lName, and salary details.
staffNo,
Union
R S
Union of two relations R and S defines a relation
that contains all the tuples of R, or S, or both R
and S, duplicate tuples being eliminated.
R and S must be union-compatible.
If R and S have I and J tuples, respectively, union is
obtained by concatenating them into one relation with a
maximum of (I + J) tuples.
Example - Union
List all cities where there is either a branch office or a
property for rent.
city(Branch)
city(PropertyForRent)
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
32 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Set Difference
R S
Defines a relation consisting of the tuples that are
in relation R, but not in S.
R and S must be union-compatible.
Example - Set Difference
List all cities where there is a branch office but no
properties for rent.
city(Branch) city(PropertyForRent)
Intersection
R S
Defines a relation consisting of
tuples that are in both R and S.
R and S must be union-compatible.
Expressed using basic operations:
R S = R (R S)
the
set
of
all
Example Intersection
List all cities where there is both a branch office and
at least one property for rent.
city(Branch)
city(PropertyForRent)
Cartesian product
R X S
Defines a relation that is the concatenation
every tuple of relation R with every tuple
relation S.
of
of
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
33 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
fName, lName(Client))
X (
of
all
clients
who
have
(Viewing))
Client.clientNo
Viewing.clientNo((
clientNo,
fName,
those
tuples
where
lName(Client))
can
be
reduced
to
Join Operations
Join is a derivative of Cartesian product.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
34 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Equivalent
to
performing
a
Selection,
using
join
predicate as selection formula, over Cartesian product of
the two operand relations.
One of the most difficult operations to implement
efficiently in an RDBMS and one reason why RDBMSs have
intrinsic performance problems.
Various forms of join operation
Theta join
Equijoin (a particular type of Theta join)
Natural join
Outer join
Semijoin
Theta join (-join)
R
FS
Defines a relation that contains tuples satisfying
the predicate F from the Cartesian product of R and
S.
The predicate F is of the form R.ai S.bi where
may be one of the comparison operators (<, , >, ,
=, ).
Can rewrite Theta join using basic Selection and
Cartesian product operations.
R
FS = F(R S)
Degree of a Theta join is sum of degrees of the operand
relations R and S. If predicate F contains only equality
(=), the term Equijoin is used.
Example - Equijoin
List the names and comments
viewed a property for rent.
(clientNo,
of
fName, lName(Client))
all
clients
Client.clientNo
who
have
Viewing.clientNo
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
35 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Natural join
R
S
An Equijoin of the two relations R and S over all
common attributes x. One occurrence of each common
attribute is eliminated from the result.
of
all
clients
who
have
Outer join
To display rows in the result that do not have matching
values in the join column, use Outer join.
R
S
(Left) outer join is join in which tuples from R
that do not have matching values in common columns
of S are also included in result relation.
street, city(PropertyForRent)
www.jntuworld.com
Semijoin
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
36 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
S
Defines a relation that contains the tuples of R
that participate in the join of R with S.
Can rewrite Semijoin using Projection and Join:
= A(R
S)
Example - Semijoin
List complete details of all staff who work at the branch
in Glasgow.
Staff
Branch
Division
R S
Defines a relation over the attributes C that consists
of set of tuples from R that match combination of every
tuple in S.
Expressed using basic operations:
T1 C(R)
T2 C((S X T1) R)
T T1 T2
Example - Division
Identify all clients who have viewed all properties with
three rooms.
( clientNo, propertyNo(Viewing))
(PropertyForRent)))
propertyNo(
rooms
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
37 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Relational Calculus
Relational calculus query specifies what is to be
retrieved rather than how to retrieve it.
No description of how to evaluate a query.
In first-order logic (or predicate calculus), predicate
is a truth-valued function with arguments.
When we substitute values for the arguments, function
yields an expression, called a proposition, which can be
either true or false.
If predicate contains a variable (e.g. x is a member of
staff), there must be a range for x.
When we substitute some values of this range for x,
proposition may be true; for other values, it may be
false.
When applied to databases, relational calculus has forms:
tuple and domain.
Tuple Relational Calculus
Interested in finding tuples for which a predicate is
true. Based on use of tuple variables.
Tuple variable is a variable that ranges over a named
relation: i.e., variable whose only permitted values are
tuples of the relation.
Specify range of a tuple variable S as the Staff relation
as:
Staff(S)
To find set of all tuples S such that P(S) is true:
{S | P(S)}
Tuple Relational Calculus - Example
To find details of all staff earning more than 10,000:
{S | Staff(S) S.salary > 10000}
To find a particular attribute, such as salary, write:
{S.salary | Staff(S) S.salary > 10000}
Query-by-Example (QBE)
Visual approach for accessing information in a database
through use of query templates.
Example values are entered into template to represent
what access to database is to achieve, such as the answer
to a query.
Originally developed by IBM in 1970s and has proved so
popular that QBE (or similar) is now provided by most
DBMSs.
When user constructs a QBE - in background, DBMS creates
an equivalent SQL statement.
www.jntuworld.com
Allows user to:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
38 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
-
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
39 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
40 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
41 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter : 06
SQL
Objectives of SQL
Ideally, database language should allow user to:
create the database and relation structures;
perform insertion, modification, deletion of data
from relations;
perform simple and complex queries.
Must perform these tasks with minimal user effort and
command structure/syntax must be easy to learn.
It must be portable.
SQL is a
components:
transform-oriented
language
with
major
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
42 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
History of SQL
In 1974, D. Chamberlin (IBM San Jose Laboratory) defined
language called Structured English Query Language
(SEQUEL).
A revised version, SEQUEL/2, was defined in 1976 but name
was subsequently changed to SQL for legal reasons.
Still
pronounced
see-quel,
though
official
pronunciation is S-Q-L.
IBM subsequently produced a prototype DBMS called System
R, based on SEQUEL/2.
Roots of SQL, however, are in SQUARE (Specifying Queries
as Relational Expressions), which predates System R
project.
In late 70s, ORACLE appeared and was probably first
commercial RDBMS based on SQL.
In 1987, ANSI and ISO published an initial standard for
SQL.
In 1989, ISO published an addendum that defined an
Integrity Enhancement Feature.
In 1992, first major revision to ISO standard occurred,
referred to as SQL2 or SQL/92.
In 1999, SQL3 was released with support for objectoriented data management.
Importance of SQL
SQL has become part of application architectures such as
IBMs Systems Application Architecture.
It is strategic choice of many large and influential
organizations (e.g. X/OPEN).
SQL is Federal Information Processing Standard (FIPS) to
which conformance is required for all sales of databases
to American Government.
SQL is used in other standards and even influences
development of other standards as a definitional tool.
Examples include:
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
43 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
44 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
SELECT Statement
SELECT [DISTINCT | ALL]
{* | [columnExpression [AS newName]] [,...] }
FROM
TableName [alias] [, ...]
[WHERE
condition]
[GROUP BY columnList] [HAVING
condition]
[ORDER BY columnList]
FROM
WHERE
GROUP BY
HAVING
SELECT
ORDER BY
Example 5.1
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
45 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
FROM Staff;
staff
Use of DISTINCT
List the property numbers of all properties that have been
viewed.
SELECT propertyNo
FROM Viewing;
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
46 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Calculated Fields
Produce a list of monthly salaries for all staff, showing
staff number, first and last names, and salary details.
SELECT staffNo, fName, lName, salary/12
FROM Staff;
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
47 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
expressive
power.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
48 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Pattern Matching
Find all owners with the string Glasgow in their address.
SELECT clientNo, fName, lName, address, telNo
FROM PrivateOwner
WHERE address LIKE %Glasgow%;
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
version
(IS
NOT
NULL)
can
test
for
non-null
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
50 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Use of COUNT(DISTINCT)
How many different properties viewed in May 01?
SELECT COUNT(DISTINCT propertyNo) AS count
FROM Viewing
WHERE viewDate BETWEEN 1-May-01
AND 31-May-01;
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
column names
aggregate functions
constants
expression involving combinations of the above.
branchNo,
COUNT(staffNo) AS count,
SUM(salary) AS sum
FROM Staff
GROUP BY branchNo
ORDER BY branchNo;
Restricted Groupings HAVING clause
HAVING clause is designed for use with GROUP BY to
restrict groups that appear in final result table.
Similar to WHERE, but WHERE filters individual rows
whereas HAVING filters groups.
Column names in HAVING clause must also appear in the
GROUP BY list or be contained within an aggregate
function.
For each branch with more than 1 member of staff, find number
of staff in each branch and sum of their salaries.
SELECT branchNo,
COUNT(staffNo) AS count,
SUM(salary) AS sum
FROM Staff
GROUP BY branchNo
HAVING COUNT(staffNo) > 1
ORDER BY branchNo;
Subqueries
Some SQL statements can have a SELECT embedded within
them.
A subselect can be used in WHERE and HAVING clauses of an
outer SELECT, where it is called a subquery or nested
query.
Subselects may also appear in INSERT, UPDATE, and DELETE
statements.
www.jntuworld.com
List staff
who work
in writer
branch
163quality
Main PDF
St.
pdfMachine
- is a pdf
that at
produces
files with ease!
Get yours
now!
53
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
is
greater
than
the
average
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Subquery Rules
ORDER BY clause may not be used in a subquery (although
it may be used in outermost SELECT).
Subquery SELECT list must consist of a single column name
or expression, except for subqueries that use EXISTS.
By default, column names refer to table name in FROM
clause of subquery. Can refer to a table in FROM using an
alias.
When subquery is an operand in a comparison, subquery
must appear on right-hand side.
A subquery
expression.
may
not
be
used
as
an
operand
in
an
Multi-Table Queries
Can use subqueries provided result columns come from same
table.
If result columns come from more than one table must use
a join.
To perform join, include more than one table in FROM
clause.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
55 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
56 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
57 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Computing a Join
Procedure for generating results of a join are:
1. Form Cartesian product of the tables named in
FROM clause.
is
an
SQL provides
product:
ORDER
special
BY
clause,
format
of
sort
result
SELECT
for
table
as
Cartesian
SELECT
[DISTINCT | ALL]
{* | columnList}
FROM Table1 CROSS JOIN Table2
Outer Joins
If one row of a joined table is unmatched, row is omitted
from result table.
Outer join operations retain rows that do not satisfy the
join condition.
Consider following tables:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
58 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
59 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Required data.
Domain constraints.
Entity integrity.
Referential integrity.
Enterprise constraints.
VARCHAR(10)
NOT NULL
Domain Constraints
(a) CHECK
sex CHAR NOT NULL
CHECK (sex IN (M, F))
CREATE DOMAIN
CREATE DOMAIN DomainName [AS] dataType
[DEFAULT defaultOption]
[CHECK (searchCondition)]
For example:
CREATE DOMAIN SexType AS CHAR
CHECK (VALUE IN (M, F));
sex SexType
NOT NULL
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Data Definition
SQL DDL allows database objects such as schemas, domains,
tables, views, and indexes to be created and destroyed.
Main SQL DDL statements are:
CREATE SCHEMA
DROP SCHEMA
CREATE/ALTER DOMAIN DROP DOMAIN
CREATE/ALTER TABLE DROP TABLE
CREATE VIEW
DROP VIEW
Many DBMSs also provide:
CREATE INDEX
DROP INDEX
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
ALTER TABLE
DROP TABLE
DROP TABLE TableName [RESTRICT | CASCADE]
www.jntuworld.com
e.g.
DROP
TABLE
PropertyForRent;
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
63 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
database.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
64 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
For example:
DROP VIEW Manager3Staff;
With CASCADE, all related dependent objects are deleted;
i.e. any views defined on view being dropped.
With RESTRICT (default), if any other objects depend for
their existence on continued existence of view being
dropped, command is rejected
Restrictions on Views
SQL imposes several restrictions on creation and use of views.
(a) If column in view is based on an aggregate function:
Column may appear only in SELECT and ORDER BY
clauses of queries that access view.
Column may not be used in WHERE nor be an argument
to an aggregate function in any query based on view.
For example, following query would fail:
SELECT COUNT(cnt)
FROM StaffPropCnt;
Similarly, following query would also fail:
SELECT *
FROM StaffPropCnt
WHERE cnt > 2;
(b) Grouped view may never be joined with a base table or a
view.
For example, StaffPropCnt view is a grouped view, so any
attempt to join this view with another table or view
fails.
Advantages of Views
Data independence
Currency
Improved security
Reduced complexity
Convenience
Customization
Data integrity
Disadvantages of Views
Update restriction
www.jntuworld.com
Structure restriction
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
65 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Performance
Transactions
SQL defines transaction model based on COMMIT and
ROLLBACK.
Transaction is logical unit of work with one or more SQL
statements guaranteed to be atomic with respect to
recovery.
An
SQL
transaction
automatically
begins
with
a
transaction-initiating
SQL
statement
(e.g.,
SELECT,
INSERT).
Changes made by transaction are not visible to other
concurrently executing transactions until transaction
completes.
Transaction can complete in one of four ways:
- COMMIT ends transaction successfully, making changes
permanent.
- ROLLBACK aborts transaction, backing out any changes
made by transaction.
- For programmatic SQL, successful program termination
ends final transaction successfully, even if COMMIT has not
been executed.
- For programmatic SQL, abnormal program end aborts
transaction.
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
GRANT
GRANT
{PrivilegeList | ALL PRIVILEGES}
ON
ObjectName
TO
{AuthorizationIdList | PUBLIC}
[WITH GRANT OPTION]
PrivilegeList consists of one or more of above privileges
separated by commas.
ALL PRIVILEGES grants all privileges to a user.
PUBLIC allows access to be granted to all present and
future authorized users.
ObjectName can be a base table, view, domain, character
set, collation or translation.
WITH GRANT OPTION allows privileges to be passed on.
Example
Give Manager full privileges to Staff table.
GRANT ALL PRIVILEGES
ON Staff
TO Manager WITH GRANT OPTION;
REVOKE
www.jntuworld.com
REVOKE takes away privileges granted with GRANT.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
67 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
68 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 07
Overview of Storage and Indexing:
Databases are stored physically as files of records, which are
typically stored on magnetic disks.
Introduction:
The collection of data that makes up a computerized
database must be stored physically on some computer storage
medium. The DBMS software that can then retrieve, update, and
process this data as needed. Computer storage media from a
storage hierarchy that includes two main categories,
Primary Storage
o The category includes storage media that can be
operated on directly by the computer Central
Processing Unit(CPU), such as the computer main
memory and smaller but faster cache memories.
Primary storage usually provides fast access to data
but is of limited storage capacity.
Secondary Storage
o This category includes magnetic disks, optical
disks, and tapes. These devices usually have a
larger capacity, cost less, and provide slower
access to data than do primary storage devices. Data
in secondary storage can not be processed directly
by the CPU: it must first be copied into primary
storage.
The storage media are classified by the speed with which
data can be accessed, by the cost per unit of data to buy the
medium, and by the mediums reliability. Lets look into the
media that are typically available.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
69 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Storage device
Hierarchy
Cache
Main Memory
Flash memory
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
70 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Magnetic Disk
Optical Disk
Magnetic Tapes
Magnetic Disks :
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
71 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
FIGURE
Types of record organization. (a) Unspanned. (b) Spanned.
Files of Unordered Records (Heap Files):
In the simplest and most basic type of organization,
records are placed in the file in the order in which they
are inserted, so new records are inserted at the end of the
file. Such an organization is called a heap
or
pile
file. Inserting a new record is very efficient: the last
disk block of the file is copied into a buffer, the new
record is added; and the block is then rewritten back to the
disk. The address of last file block is kept in the file
header.
Files or Ordered Records (Sorted Files)
We can physically order the records of a file on disk
based on the value of one of their fields- called the
ordering field. This leads to an ordered or sequential file.
If the ordering field is also a key field of the file a
field guaranteed to have a unique value in each record- then
the field is called the ordering key for the file. Figure
shows an ordered file with name as the ordering key field
assuming that employees having distinct names.)
Figure :
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
73 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Hashing Technique:
A type of primary file organization is based on hashing,
which provides very fast access to records on certain search
conditions. This organization is usually called hash file.
The search condition is must be an equality condition on a
single field, called the hash field of the file. In most
cases, the hash field is also a key field of the file, in
which case it is called hash Key. The idea behind hashing is
to provide a function h, called a hash function or
randomizing function that is applied to the hash field value
of a record and yields the address of the disk block in
which the record is stored. A search for the record within
the block can be carried out in a main memory buffer.
Internal Hashing:
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
74 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
FIGURE:
Internal
hashing
data
structures.
(a) Array of M positions for use in internal hashing.
(b) Collision resolution by chaining records.
www.jntuworld.com
External Hashing for Disk files:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
75 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
block of the data file and the keys of its anchor record
rather than for every search values( or every record).
Clustering Indexes:
If records of a file are physically ordered on a non key
field- which does not have a distinct value for each recordthat field is called the clustering field. We can create a
different type of index, called clustering index, to speed up
the retrieval of records that have the same value for the
clustering field. This differs from a primary index, which
requires that the ordering field of the data file have a
distinct value for each record. A clustering index is also an
ordered file with two fields.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
78 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
79 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
80 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 08
Query Evaluation overview
Introduction
In network and hierarchical DBMSs, low-level procedural
query
language
is
generally
embedded
in
high-level
programming language.
Programmers responsibility to select most appropriate
execution strategy.
With declarative languages such as SQL, user specifies what
data is required rather than how it is to be retrieved.
Relieves user of knowing what constitutes good execution
strategy.
Also gives DBMS more control over system performance.
Two main techniques for query optimization:
heuristic rules that order operations in a query;
comparing different strategies based on relative costs, and
selecting one that minimizes resource usage.
Disk access tends to be dominant cost in query processing
for centralized DBMS.
Query Processing
Activities involved in retrieving data from the database.
Aims of QP:
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
81 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Query Optimization
Activity of choosing
processing query.
an
efficient
execution
strategy
for
(2)
(position='Manager') (city='London')(Staff
Staff.branchNo=Branch.branchNo
(3) (
Branch)
position='Manager'(Staff)
city='London'
Staff.branchNo=Branch.branchNo
(Branch))
Assume:
1000 tuples in Staff; 50 tuples in Branch;
50 Managers; 5 London branches;
no indexes or sort keys;
results of any intermediate operations stored
disk;
cost of the final
write is ignored;
www.jntuworld.com
tuples
are
accessed
at quality
a time.
pdfMachine - is a pdf writer that one
produces
PDF files with ease!
Get yours
now!
82
on
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Cost Comparison
Cost (in disk accesses) are:
(1)
(2)
(3)
decomposition
(consisting
validation);
optimization;
code generation;
execution.
of
parsing
and
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Cost
Database Statistics
Success of estimation depends on amount and currency of
statistical information DBMS holds.
Keeping statistics current can be problematic.
If statistics updated every time tuple is changed, this
would impact performance.
DBMS could update statistics on a periodic basis, for
example nightly, or whenever the system is idle.
query
optimization:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
84 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Rule-based
15 rules, ranked in order of efficiency. Particular
access path for a table only chosen if statement contains
a predicate or other construct that makes that access
path available.
Score assigned to each execution strategy using these
rankings and strategy with best (lowest) score selected.
When 2 strategies produce same score, tie-break resolved
by making decision based on order in which tables occur
in the SQL statement.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
85 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
QO in Oracle Cost-Based
To improve QO, Oracle introduced cost-based optimizer in
Oracle 7, which selects strategy that requires minimal
resource use necessary to process all rows accessed by
query (avoiding above tie-break anomaly).
User can select whether minimal resource usage is based
on throughput or based on response time, by setting the
OPTIMIZER_MODE initialization parameter.
Cost-based optimizer also takes into consideration hints
that the user may provide.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
86 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 9
Transaction Processing:
Transaction:
Action, or series of actions, carried out by user or
application, which accesses or changes contents of database.
It Transforms database from one consistent state to another,
although consistency may be violated during transaction.
Single User Vs. Multi User Systems:
A DBMS is a single user if at most one user at a time can
use the system, and it is multi user if many users can use the
system and hence access the database concurrently. Multiple
users can access databases and use the computer systems
Simultaneously because of the concept of Multiprogramming,
which allows the computer to execute multiple programs or
processes at the same time. If only a single central
processing unit(CPU) exists, it can actually executes at most
one process at a time. However multiprogramming operating
systems executes some commands from one process then suspend
that process and execute some commands from the next process,
and so on. A process is resumed at the point where it was
suspended whenever it gets its turn to use the CPU again.
Hence concurrent execution of process is actually interleaved
as illustrated in the following figure, which shows two
processes A and B executing concurrently in an interleaved
fashion.
Vs.
Parallel
Processing
of
www.jntuworld.com
Transaction Support
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
87 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Properties of Transactions
Four basic (ACID) properties of a transaction are:
Atomicity
Consistency
Isolation
Durability
:Effects
of
a
committed
transaction
are
permanent and must not be lost because of later
failure.
from
one
consistent
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
88 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Concurrency control:
Processes of managing simultaneous operations on
database without having them interfere with one another.
Prevents interference when two
accessing database simultaneously
updating data.
or
and
the
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
90 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
91 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
FIGURE
Some problems
that occur when concurrent
uncontrolled. (c) The incorrect summary problem.
execution
is
Serializability
Objective of a concurrency control protocol is to
schedule transactions in such a way as to avoid any
interference.
Could run transactions serially, but this limits degree
of concurrency or parallelism in system.
Serializability
identifies
those
executions
of
transactions guaranteed to ensure consistency
Schedule
Sequence
transactions.
of
reads/writes
by
set
of
concurrent
Serial Schedule
Schedule where operations of each transaction are
executed consecutively without any interleaved operations from
other transactions.
No guarantee that results of all serial executions of a
given set of transactions will be identical.
Nonserial Schedule
Schedule
where
operations
transactions are interleaved.
from
set
of
concurrent
Serializability
In serializability, ordering of read/writes is important:
(a)
If two transactions only read a data item, they do not
conflict and order is not important.
(b)
If two transactions either read or write completely
separate data items, they
do not conflict and order is not
www.jntuworld.com
important.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
92 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Serializability
Conflict serializable schedule orders any conflicting
operations in same way as some serial execution.
Under constrained write rule (transaction updates data
item based on its old value, which is first read), use
precedence graph to test for serializability.
Precedence Graph
Create:
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
93 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
View Serializability
Offers less stringent definition of schedule equivalence
than conflict serializability.
Two schedules S1 and S2 are view equivalent if:
For each data item x, if Ti reads initial value of x
in S1, Ti must also read initial value of x in S2.
For each read on x by Ti in S1, if value read by x
is written by Tj, Ti must also read value of x
produced by Tj in S2.
For each data item x, if last write on x performed
by Ti in S1, same transaction must perform final
write on x in S2.
Schedule is view serializable if it is view equivalent to
a serial schedule.
Every
conflict
serializable
schedule
is
view
serializable, although converse is not true.
It can be shown that any view serializable schedule that
is not conflict serializable contains one or more blind
writes.
In general, testing whether schedule is serializable is
NP-complete.
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
94 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Recoverability
Serializability
identifies
schedules
that
maintain
database consistency, assuming no transaction fails.
Could also examine recoverability of transactions within
schedule.
If transaction fails, atomicity requires effects of
transaction to be undone.
Durability states that once transaction commits, its
changes cannot be undone (without running another,
compensating, transaction).
Locking,
Timestamping.
Both are conservative approaches: delay transactions in
case they conflict with other transactions.
Optimistic methods assume conflict is rare and only check
for conflicts at commit.
Locking
Transaction uses locks to deny access to other transactions
and so prevent incorrect updates.
Most widely used approach to ensure serializability.
Generally, a transaction must claim a shared (read) or
exclusive (write) lock on a data item before read or
write.
Lock prevents another transaction from modifying item or
even reading it, in the case of a write lock.
Locking - Basic Rules
www.jntuworld.com
If transaction has shared
lock on item, can read but not
update
item.
pdfMachine
- is a pdf writer that produces quality PDF files with ease!
Get yours
95 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
operations
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Deadlock
An impasse that may result when two (or more) transactions are
each waiting for locks held by the other to be released.
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Deadlock Prevention
DBMS looks ahead to see if transaction would cause
deadlock and never allows deadlock to occur.
Could order transactions using transaction timestamps:
Wait-Die - only an older transaction can wait for
younger one, otherwise transaction is aborted (dies)
and restarted with same timestamp.
Wound-Wait - only a younger transaction can wait for
an older one. If older transaction requests lock
held by younger one, younger one is aborted
(wounded).
that
indicates
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
98 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Three phases:
Read
Validation
Write
validation
phase
for
update
A file.
of
protection
by
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
99 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Database Recovery
Process of restoring database to a correct state in the event
of a failure.
Need for Recovery Control
Two types of storage: volatile (main memory) and
nonvolatile.
Volatile storage does not survive system crashes.
Stable storage represents information that has been
replicated in several nonvolatile storage media with
independent failure modes.
Types of Failures
System crashes, resulting in loss of main memory.
Media failures, resulting in loss of parts of secondary
storage.
Application software errors.
Natural physical disasters.
Carelessness or unintentional destruction of data or
facilities.
www.jntuworld.com
Sabotage.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
100 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
DBMS starts at time t0, but fails at time tf. Assume data
for transactions T2 and T3 have been written to secondary
storage.
T1 and T6 have to be undone. In absence of any other
information, recovery manager has to redo T2, T3, T4, and
T5.
Recovery Facilities
DBMS should provide following facilities to assist with
recovery:
Log File
Contains information about all updates to database:
Transaction records.
Checkpoint records.
Often used for otherwww.jntuworld.com
purposes (for example, auditing).
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
101 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Checkpoint
Point of synchronization between database and log file.
All buffers are force-written to secondary storage.
Checkpoint record is created containing identifiers of
all active transactions.
When failure occurs, redo all transactions that committed
since the checkpoint and undo all transactions active at
time of crash.
In previous example, with checkpoint at time tc, changes
made by T2 and T3 have been written to secondary storage.
Thus:
only redo T4 and
T5,
www.jntuworld.com
undo
transactions
T1 and T6.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
102 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Recovery Techniques
If database has been damaged:
Need to restore last backup copy of database and
reapply updates of committed transactions using log
file.
If database is only inconsistent:
Need to undo changes that caused inconsistency. May
also need to redo some transactions to ensure updates
reach secondary storage.
Do not need backup, but can restore database using
before- and after-images in the log file.
Main Recovery Techniques
Three main recovery techniques:
Deferred Update
Immediate Update
Shadow Paging
Deferred Update
Updates are not written to the database until after a
transaction has reached its commit point.
If transaction fails before commit, it will not have
modified database and so no undoing of changes required.
May
be
necessary
to
redo
updates
of
committed
transactions as their effect may not have reached
database.
Immediate Update
Updates are applied to database as they occur.
Need to redo updates of committed transactions following
a failure.
May need to undo effects of transactions that had not
committed at time of failure.
Essential that log records are written before write to
database. Write-ahead log protocol.
If no transaction commit record in log, then that
transaction was active at failure and must be undone.
Undo operations are performed in reverse order in which
they were written to log.
Shadow Paging
Maintain two page tables during life of a transaction:
www.jntuworld.com
current page and shadow page table.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
103 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Chapter 10
Normalization
Main objective in developing a logical data model for
relational database systems is to create an accurate
representation of the data, its relationships, and
constraints.
To achieve this objective, must identify a suitable set
of relations.
Four most commonly used normal forms are first (1NF),
second (2NF) and third (3NF) normal forms, and BoyceCodd
normal form (BCNF).
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
104 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
form
to
Data Redundancy
Major aim of relational database design is to group
attributes into relations to minimize data redundancy and
reduce file storage space required by base relations.
Problems associated with data redundancy are illustrated
by comparing the following Staff and Branch relations
with the StaffBranch relation.
Data Redundancy
of
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
105 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Relations
that
contain
redundant
information
potentially suffer from update anomalies.
may
Determinant
of
a
functional
dependency
refers
to
attribute or group of attributes on left-hand side of the
arrow.
Example - Functional Dependency
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
106 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
dependencies
for
given
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
107 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
109 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
if
and
only
if
every
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
110 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
111 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
5NF - Example
More Notes:
Inference Rules for FD
Reflexive Rule :
if X Y, then XY
Augmentation Rule :
{XY} = XZ
Transitive Rule:
{XY, YZ} = XZ
Decomposition or Projective Rule
{XYZ } = XY
Union or additive Rule :
{XY , X Z} = XYZ
Pseudo Transitive Rule:
{XY, WYZ} = WXZ
Minimal sets of FD
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
114 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
115 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
SHOW USER
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
116 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
DECLARE
<declaration>
BEGIN
SUB-BLOCK1
DECLARE
<declarations>
BEGINwww.jntuworld.com
<executable
statement>
pdfMachine - is a pdf
writer that
produces quality PDF files with ease!
Get yours
117 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
EXCEPTION
<Exception handlers>
END;
SUB-BLOCK2
DECLARE
<declarations>
BEGIN
<executable statements>
<EXCEPTION>
<exception handlers>
END;
END;
Referring to the following sample PL/SQL block we have the following example.
DECLARE
Num_in_stock NUMBER(5);
BEGIN
SELECT quantity INTO num-in-stock FROM inventory_table
WHERE product = TENNIS RACQUET;
IF num_in_stock>0 THEN
UPDATE INVENTORY_TABLE SET quantity = quantity 1
WHERE product = THNNIS RECQUET;
INSERT INTO purchase_record
VALUES (TENNIS RACQUET PURCHASED., SYSDATA);
ELSE
INSERT INTO purchase_record
VALUES(OUT OF TENNIS RACQUETS.,SYSDATA);
END IF;
COMMIT;
END;
Advantages of PL/SQL
PL/SQL is a completely portable high performance transaction processing language
which provides the following advantages:
Support for Sql:PL/SQL lets us to use all SQL data manipulation, cursor control and transaction
control commands as well as SQL functions, operators, and pseudocolumns.
Higher Productivity:-
www.jntuworld.com
PL/SQL adds functionality to non-procedural
tools such as SQL*Forms, SQL*
Reportwriter
SQL*Menu.
With
PL/SQL
in these tools
youPDF
canfiles
use familiar
procedural
pdfMachine
- is a pdf
writer
that produces
quality
with ease!
Get yours
now!
118
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
PL/SQL is not case sensitive, so lower-case letters are equivalent to the corresponding
upper-case letters except within string (when surrounded by single quotes) or represent
the value of a character variable.
Delimiters:A delimiters is a simple or compound symbol that has a special meaning to PL/SQL. A
few examples are given below.
;
%
statement terminator
Attribute indicator (cursor attributes like % is open and indirect declaration
attributes like % Rowtype
Single underscore: (single byte wildcard symbol as in SQL.
:
Host variable indicator
<<and>>Label delimiters
:=
Alignment operator
__
Single line comment
/* and */ Beginning and ending multilane comment block delimiters.
Identifiers:An indentifier is a name for a PL/SQL object which includes constants, variables,
exceptions, cursors, subprograms, packages, and reserved words. The properties of
www.jntuworld.com
identifiers are:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
119 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
1.
2.
3.
4.
Binary Integer:It allows to stroe signed integers (-2^31 1 through 2 ^31- Natural and positive are both
subtypes of Binary-integer
Natural allows 0 through 2 ^31
Positive allows 1 through 2 ^31
Number
Use the number data type to store fixed or floating point numbers of any size. The
maximum precision of a variable with Number type is 38 digits. While declaring we can
optionally specify the valuable precision as follows:
Number (precision, Scale)
The precision of a Number is the total number of digits. The scale dictates the number
of digits to the right or left of the decimal point at which rounding occurs. The
remaining data types in number are all sub types of number. They have the same range
of values as their base type. The remaining data types in number are all sub types of
number. They have the same range of values as their base type.
Subtype
Datatype
Dec(prec.scale)
Decimal(prec.scale)
Double Precision
Float (Binary)
Int
Integer
Numeric (Prec, Scales)
Real
Smallint
Number(prec, Scale)
Number(prec.scale)
Number
Number
Number(38)
Number(38)
Number(prec, Scale)
Number
Number(38)
Char
Variables with character data types store text and are manipulated by character
functions. The CHAR data type takes an optional parameter that lets you specify a
maximum length upto 32767 bytes. The syntax is:CHAR (maximum_length)
Char Subtypes
www.jntuworld.com
The character subtypes have the same
rang of values as their base type.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
120 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Character
Varchar 2
It has the same syntax as Char. But the difference is, if we assign a character value to a
Char variable and if the length is shorter than the declared length of the variable
PL/SQL blankpads the value to the declared length. The VARCHAR is a subset of
VARCHAR2.
If we assign a character value to a Varchar2 variable, and if the value is shorter than
the declared length of the variable, PL/SQL neither blankpads the value nor strips
trailing blanks.
Name1 Char (10);
Name2 Varchar2(10);
If we give name1 and name2 as Frank, name 1 will be stored internally as Frank and
name2 as Frank. So even though the names are same since the data types are different
they are not same.
Long:The variable LONG can store variable-length strings of up to 32760 bytes which is
seven fewer bytes longer than allowed in Varchar2 type variables.
Date:The Date data type is to store fixed length data values. It also takes no parameters.
Valid dates include from Jan 1,4712 BC to December 31,4712 AD. When stored in a
database column, date values include to the first day of the current month; the time
portion defaults to midnight.
Declare Variable:Variable are declared in the DECLARE section of the PL/SQL block. Declaration
involves the name of the variable followed by its data type. All statements must end
with a semicolon. Initial values can also be assigned at the time of declaration.
Constants are declared by specifying the key work CONSTANT before the data type.
The syntax is:Indentifier [Constant] Data Type [Not Null] [:=Pl/Sql Expression];
Example:
Declare
Number
Count
Number (9,2)
Secs_Per_Day Constant
Number:= 60*60*24
First_Name
Char
Last Name
Varchar2
Birth_Day
Date
www.jntuworld.com
Available
Boolean := Null;
Begin
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
121 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
..
..
Comparisions
PL/SQL supports the comparison of variables and constants in SQL and PL/SQL
statements. These comparisons called Boolean expressions, generally consists of simple
expressions separated by Relational operators (=,!=,<,>, >=, <=). Boolean expressions
are often connected by the logical operators AND, OR, NOT. In PL/SQL a Boolean
expression always evaluates to TRUE, FALSE OR NULL. In a SQL statement Boolean
expression allow you to control which rows in a table are affected by the statement. In a
non SQL statement, Boolean expressions are the basis for conditional control.
There are three kinds of Boolean expression Numeric, Character, Date.
Boolean Expression:A character string is a sequence of characters stung together. Like numeric
expressions, character string can be compared. The comparison is based on the
alphabetic ordering.
ename>empname
ename != frank
Operator
Meaning
=
!=
<
>
<=
Is the Same As
Is Not The Same As
Comes Alphabetically before
Comes Alphabetically After
Comes Alphabetical Before
Declaring Variables and Constants:PL/SQL supports a variety of data types that you can use for declaring variables and
constants. You can assign values to variables as you declare them and you can change
the value of a variable through further assignments.
You must assign the value of a constant to it when you declare it, this value is fixed and
cannot be changed at run time.
Example variable declarations are given below:DECLARE
V_NUM1 NUMBER NOT NULL:=10109;
NUM8 NUMBER(3,1);
XYZ NUMBER(2,2):=31.8;
ABC12 NUMBER(9,2):=XYZ*131;
V_CHR1 CHAR(89);
V_CHR2 VARCHAR2(12):= JANUARY;
www.jntuworld.com
TODAY DATE:= SYSDATE;
TRUEFALSE
BOOLEAN;
pdfMachine
- is a pdf writer that produces quality PDF files with ease!
Get yours
122 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
123 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Control structures are the most important PL/SQL extensions to SQL. Not only does
PL/SQL let you manipulate data, it lets you process the data using conditional, iterative,
sequential, and unconditional flow-control statements such as if-then-else, for loop,
while-loop, exit-when and goto.
Control Structures:There are three types of control statements. Conditional control, Iterative control and
Sequential control. The conditional control returns a Boolean value. The iterative
control executes a sequence of statements repeatedly. The sequential statements execute
a sequence of statements in the order in which they occur.
Conditional Control:The IF statement lets you execute a series of statements conditionally. There are three
forms IF-THEN, IF-THEN-ELSE, and IF-THEN-ELSIF.
If-then
IF associates a condition with a sequence of statements enclosed by the keywords THEN
and END IF. The statements are executed only when the condition is TRUE.
IF condition THEN
Sequence of statements;
END IF;
Example:
IF Sales>Quata THEN
Combute_bonus(empid);
UPDATE payrole SET pay + bonus WHERE EMPNO = EMP_ID;
END IF;
If-then-else
The second form of IF statements adds the keywords ELSE followed by alternative
sequence of statements. The sequence of statements in the ELSE clause will be executed
only when the condition evaluates to FALSE.
IF condition THEN
Sequence of statement
ELSE
Sequence of statements
END IF;
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
124 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
The third form introduces the keyword ELSIF to introduce additional conditions. If
any condition evaluates to TRUE then that sequence of statements get executed. We
can have any number of ELSIF clause but the last one is optional.
If conditiona 1 THEN
Sequence of statements;
ELSIF
Sequence of statements;
ELSIF
Sequence of statements;
END IF;
An example of if-then-else structure is as follows.
SQL>declare
2 length number(3):=10;
3 breadth number(3):=12;
4 area number(5);
5 begin
6 if length>=0 then
7 if breadth <=0 then
8 dbms_output.put_line(Breadth cant be less than 0);
9 else
10 area:=.5 * length * breadth;
11 dbms_output.put_line(Breadth cant be less than 0);
12 end if;
13 else
14 dbms_output.put_line(Length cant be less than 0);
15 end if;
16 end;
17/
Area is 60
PL/SQL procedure successfully completed.
Iterative Control
Loop statements lets you use the iterative type of control. There are three forms of
LOOP statements. LOOP, WHILE-LOOP and FOR-LOOP.
Loop
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
125 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
The simplest form is the infinite LOOP, WHICH encloses sequence of statements
between the key words LOOP and END LOOP.
LOOP
Sequence of statements;
END LOOP;
Exit
The EXIT statement is used to complete the loop. You can place one or more EXIT
statement inside a LOOP. The EXIT-WHEN statement allows a loop to complete
conditionally when the condition in the WHEN clause is evaluated.
Loop
If..then
Exit; - Exit Loop
End If;
End Loop;
Loop
Fetch C1 Into
Exit When C1% Notfound
End Loop;
Example
SQL>declare
2 counter binary_integer:=1;
3 begin
4 loop
5 dbms_output.put_line(Counter values is || counter);
6 demb_output.put_line( );
7 counter:=counter+1;
8 exit when counter>5;
9 end loop;
10 end;
/
Counter values is 1
Counter values is 2
Counter values is 2
Counter values is 3
Counter values is 5
PL/SQL procedure successfully completed.
Loop Labels
Like PL/SQL blocks LOOPS can be labeled. The label, an undeclared identifier enclsed
by double angle brackets, must appear at the beginning of the LOOP statement as
follows:
www.jntuworld.com
<<label_name>>
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
126 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Loop
.
End Loop Label_Name;
<<Outer Block>>
While-loop
The WHILE-LOOP statement associates a condition with a sequence of statement
enclosed by the keywords LOOP and END LOOP. Before each iteration of the LOOP,
the condition is evaluated. If the condition evaluates to TRUE the sequence of
statements are evaluated else the loop is by passed.
While Condition Loop
Sequence Of Statements:
Endloop;
Consider the following example. This block uses a simple WHILE loop to insert 5 rows
into a table. The values of a counter variable, and either of two character strings are
inserted. Which string is inserted depends on the value of the loop index.
<SQL> create table TEMP
2 (coll number(9,4));
Table created.
<SQL>DECLARE
2 x NUMBER: = 100;
3 BEGIN
4 WHILE x<501 LOOP
5 INSERT INTO TEMP VALUES (X);
6 x:= x+100;
7 END LOOP;
8 COMMIT;
9 END;
10 /
PL/SQL procedure successfully completed.
For-loop
The number of iterations through a WHILE-LOOP is unknown. The number of
iterates through a FOR-LOOP is known before it enters the LOOP, FOR-LOOP
iterates over a specified range of integers. The syntax is as follows:
For example consider the following example which will check the value I is even or odd
and inserts the data accordingly.
SQL>create table TEMP
2 (col1 number(9,4),
www.jntuworld.com
3 (col2 number(4),
4 text char(55));
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
127 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Table created
SQL>DECLARE
2 x NUMBER:=100;
3 BEGIN
4 FOR I IN 1..5 LOOP
5 IF MOD(I,2) =0 THEN I is even
6 INSERT INTO temp VALUES(i,x, i(even);
7 ELSE
8 INSERT INTO temp VALUES(i,x, i(odd);
9 END IF;
10 x:=x+100;
11 END LOOP;
12 COMMIT;
13 END;
14/
GOTO test_line;
...
<<test line>>
END;
A GOTO cant branch into an IF statement, LOOP statement or sub block.
Also it cant branch from one IF statement clause to another.
A GOTO cant branch out of a subprogram.
A GOTO statement cant branch from an exception handler into the current
www.jntuworld.com
block.
UsepdfMachine
of GOTO is- is
a complex
unstructured
coding.
a pdf writer
that produces
quality PDF files with ease!
Get yours
now!
128
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
NULL STATEMENT
The NULL statement specified inaction, it does nothing other than pass control to the
next statement. It can, however, improve readability. In a construct allowing
alternative actions, the NULL statement serves as a place holder.
If
Score>100 Then
Compute_Bonus(Batsma_Id);
Else
Null;
End If:
Cursors
A cursor is a variable that runs through the tuples of some relation. This relation can
be a stored table, or it can be the answer to some query. By fetching into the cursor
each tuple of the relation, we can write a program to read and process the value of each
such tuple. If the relation is stored, we can also update or delete the tuple at the current
cursor position.
To process a SQL statement, PL/SQL opens work are called private SQL area. PL/SQL
allows user to name the private work areas and access the stored information. The
PL/SQL construct to identify each and every work area used is called CURSOR. There
are two types of cursors namely IMPLICIT and EXPLICIT.
Explicit Cursor
The set of rows returned by a query can consist of Zero, one or many rows, depending
upon the number of rows that meet the querys search condition. When a query returns
multiple rows, a cursor can be explicitly defined to:
1) process beyond the first row returned by the query.
2) Keep track of which row is being processed.
There are four steps to DECLARE and USE A CURSOR:
DECLARE the cursor
Open the cursor
FETCH data from the cursor
CLOSE the cursor
Declare Cursor
Declare the cursor to associate its name with a select statement. Forward references are
not allowed in PL/SQL. So we must declare cursor before referencing in other
statements.
DECLARE
www.jntuworld.com
CURSOR<cursor_name>IS
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
129 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
< select statement>:
Example:
CURSOR MY_FIRST IS SELECT ENAME FROM EMP
WHERE SAL>7000;
The select statement must not include the INTO clause
Values can be assigned to cursor name
Declared cursors are scoped just as variables
Open Cursor
Opening the cursor executes the query and identifies the active set which consists of all
rows that meet the query search criteria.
OPEN<cursor_name>;
Fetch Cursor
The fetch statement retrieves the rows in the active set one at a time. Each time the
fetch is executed the cursor and advances to the next row in the active set.
FETCH<cursor_name>INTO<var, var2..>;
For each column value returned by the query associated with the cursor, there must be
a corresponding variable in the INTO list. Their datatypes must also be compatible.
Close Cursor
Close the cursor to free up the resources. The close statement disables the cursor and
the active set becomes undefined. No more rows can be fetched from a closed cursor.
CLOSE<cursor_name>;
Example
SQL>DECLARE CURSOR c1 IS
2 SELECT ename, sal FROM emp;
3 name emp.ename%type;
4 salary emp.sal%type;
5 BEGIN
6 OPEN
7 for I in 1..5
8 LOOP
9 FETCH c1 INTO name, salary;
10 dbms_output.put_line(Name is || name || Salary is|| salary);
11 end loop;
12 close c1;
13 end;
www.jntuworld.com
14/
Name is SMITH
Salary
pdfMachine
- isisa1000
pdf writer that produces quality PDF files with ease!
Get yours
130 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
What Is A Subprogram?
Subprograms are PL/SQL blocks that can take parameter and can be invoked.
www.jntuworld.com
PL/SQL has two types of subprograms
PROCEDURES and FUNCTIONS.
procedurepdfMachine
is used to perform
anwriter
actionthat
andproduces
a function
to compute
a value.
- is a pdf
quality
PDF files
with ease!
Get yours
now!
131
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
be a different procedure of the same name, you will not be warned, and the old
procedure will be lost.
There can any number of parameters, each followed by a mode and a type. The
possible modes are IN (read-only), OUT(write-only), and INOUT(read and write).
BEGIN
Addtyple1(99);
END;
The following procedure also inserts a tuple into T2, but it takes both components as
arguments:
CREATE PROCEDURE addtuple2(
xT2,a%TYPE
y T2,b%TYPE)
AS
BEGIN
INSERT INTO T2(A,B)
VALUES(x,y);
END addtuple2;
Now, to add a tuple2(10, abc) to T2:
BEGIN
Addtyple2(10, abc);
END;
The following illustrates the use of an OUT parameter:
CREATE TABLE T3 (
a INTEGER,
b INTEGER
);
CREATE PROCEDURE addtuple3(a NUMBER, b OUT NUMBER)
AS
BEGIN
B :=4;
INSERT INTO T3 VALUES(A,B);
END;
DECLARE
v NUMBER;
BEGIN addtuple3(10,v);
END;
Note that assigning values to parameters declared as OUT or INOUT causes the
corresponding input arguments to be written. Because of this, the input argument for
an OUT or INOUT parameter should be something with an lvaluse, such as a
variable like v in the example above. A constant or a literal argument should not be
passed in for an OUT/INOUT parameter.
www.jntuworld.com
Another Example:
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
133 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
The function below demonstrates the syntax of a PL/SQL function block, note that as
with a procedure the OR REPLACE clause can be left out if you dont want the
replacement of an existing function with the same name. Function definition vary from
procedure definitions in that you must explicitly name a variable to return and you
must return a value in the variable via the RETURN statement.
CREATE OR REPLACE FUNCTION MYFUNC1
RETURN NUMBER
IS salary NUMBER(5);
BEGIN
SELECT SAL INTO salary FROM EMP where empno = 7369;
RETURN (salary);
END MYFUNC1;
Functional Sal_Ok (Salary Real, Title Read)
Return Boolean Is
Min_Sal Real;
Max_Sal Real;
Begin
Select Losal, Hisal Into Min_Sal, Max_Sal
From Sals Where Job = Title;
Return (Salary>=Min_Sal) And
(Salary <=Max_Sal);
End Sal_Ok;
If the salary is out of range sal_ok is set to false; otherwise, sal_ok is set to true. A
function is called as a part of an expression. The function sal_ok is called as
IF SAL_OK(NEW_SAL, NEW_TITLE) THEN
ELSE
END IF;
Functions should not be called inside SQL statements.
A RETURN statement immediately completes the execution of subprogram and returns
control to the caller. A subprogram can contain several return statement. Executing
any one of them completes the program.
Function Balance (Acc_Id Integer) Return Real Is
Acct_Bal Real;
Begin
Select Bal Into Acct_Bal From Accts
Where Acct No = Acct_id;
Return Acct_Bal;
End Balance;
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
135 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
Introduction to Triggers:Triggers are a special PL/SQL construct similar to procedures. However, a procedure
is executed explicitly from another block via a procedure call, while a trigger is executed
implicitly whenever the triggering event happens.
ORACLE allows you to define procedures that are implicitly executed when an insert,
update, delete statement is issued against the associated table. These procedures are
called database triggers. Triggers can be defined only on tables and not on views. The
triggers which we use in FORMS are different since they are fired only when a trigger
point is executed with in a specific application in FORMS. The database trigger is
executed against a table, no matter what user or application issues the statement (insert,
update, delete). So the triggering event is either a INSERT, DELETE, or UPDATE
command.
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
attribute(s) in <table_name>. If present, the OF clause defines the event to be
only an update of the attribute(s) listed after OF. Here are some examples:
INSERT ON R
INSERT OR DELETE OR UPDATE ON R
UPDATE OF A,B OR INSERT ON R
If FOR EACH ROW option is specified, the trigger is row-level; otherwise, the
trigger is statement-level.
For a row-level trigger, a trigger restriction can be specified in the WHEN
clause, enclosed by parentheses. The trigger restriction is a SQL condition that
must be satisfied in order for ORACLE to fire the trigger. This condition cannot
contain subqueries. Without the WHEN clause, a trigger is fired by every
triggering event.
<trigger_body> is a PL/SQL block, rather than sequence of SQL statements.
Oracle has placed certain restrictions on what you do in <trigger_body>, in
order to avoid situations where one trigger performs an action that triggers a
second trigger, which then triggers a third, and so on, which could potentially
create an infinite loop.
The restrictions on <trigger_body> include:
You cannot modify the same relation whose modifiction is the event triggering
the trigger.
You cannot modify a relation connected to the triggering relation by another
constraint such as a foreign-key constraint.
Types of Triggers
There are two kinds of triggers namely
DML triggers and
Instead-of triggers
In the case of DML triggers you can write triggers for insert, update or delete
operations on a detabase table. In the case of instead-of triggers you can define triggers
even on views. This kind of triggers can be defined on views only.
The general syntax of triggers is given below:
Create [or replace] trigger trigger_name
{ Before | After | Instead of } triggering_event
referencing_clause
[when trigger_condition]
[for each row]
trigger_body;
In the above syntax trigger name refers to the name of the trigger, triggering event
specifies the event that fires the trigger. The referencing clause is used to refer to the
data in the row currently being modified, trigger condition is a valid condition in the
www.jntuworld.com
when clause and trigger_body is the
main code of the trigger.
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
137 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA
www.jntuworld.com
www.jwjobs.net
Data Base Management Systems
There are two levels of triggers namely ROW level and STATEMENT level. A row
trigger is fired for each time the table is affected by the triggering statement. A
statement type trigger is fired once on behalf of the triggering statement regardless of
the number of rows in the table affected.
TRIGGER TIMING
BEFORE triggers execute the trigger action before the triggering statement. AFTER
triggers execute the action after the triggering statement is executed. So with these
combinations we can create four types as follows:
www.jntuworld.com
pdfMachine - is a pdf writer that produces quality PDF files with ease!
Get yours
138 now!
Thank you very much! I can use Acrobat Distiller or the Acrobat PDFWriter but I consider your
product a lot easier to use and much preferable to Adobe's" A.Sarras - USA