Rdbms Notes
Rdbms Notes
INTRODUCTION:-
DATA
INPUT PROCESSING OUTPUT DATA
http://www.saif4u.webs.com
2
File processing systems are still widely used today, especially for backing up
database systems.
To be useful for business applications, computers must be able to store,
manipulate, and retrieve large files of data. Computer file processing systems were
developed for this purpose.
As business applications became a more complex, it become evident that
traditional file processing systems had a number of short comings and limitations.
As a result, these systems have been replaced by database processing systems
File processing systems are still widely used today, especially for backing up
database systems.
File Organization: - Maintenance of the records in a file is called File
Organization.
Evolution of DBMS:-DBMS were first introduced during the 1960s and have
continued to evolve during subsequent decades.
1960s:- Traditional file systems and first database management systems were
introduced.
1970s:- Hierarchical and Network data base models also known as first generation
DBMS
1980s:- Relational model also known as second generation DBMS.In Relational
model, all data are represented in the form of tables. A relatively simple fourth-
http://www.saif4u.webs.com
3
generation language called SQL (for Structured Query Language) is used for data
retrieval.
1990s:- Object-Oriented and Object-Relational data model
DBMS were developed to overcome the limitations of file processing systems.
Users of DBMS:-
Users are of two types
1) The people whose jobs involve the day to day use of a large database.
2) The people who work to maintain the database system environment.
1. DataBase Administrators: - The DBA is responsible for authorizing access to
the database, for coordinating and monitoring its use, and for acquiring software
and hardware resources as needed.
2. Database Designers: - Database designers are responsible for identifying the
data to be stored in the database and for choosing appropriate structures to
represent and store this data.
3. End users: - End Users are the persons, whose jobs require access to the
database for quering, updating, and generating reports.
4. System Analysts and Application Programmers: - Systems analysts determine
the requirements of end users, and develop specifications for canned transactions
that meet these requirements.
Network data model: - data in the network model are represented by collection of
records and relationships among data are represented ny links. The links can be
http://www.saif4u.webs.com
4
Relational Model:- The relational model represents data and relationships among
data by a collection of tables.each of which has a columns with unique names.The
following relational database showing Customers and Accounts they have.
i) Serial File Organisation: Here the records are stored one after another and
accessed in the same manner. In order to get particular records, all the
previous records must be read to access the required records. There is no
logical order in this method File Organisation.
a) It is a simple and easy to understand.
b) It is the cost effective method.
c) It needs only one key record to locate.
d) There is full utilization of storage space.
e) This method is very slow as the entire file must be processed.
Ex:
10 7 6 12 25
th
To reach the 12 number record, we should surpass first three
records.
f) In this method updation i.e. addition, deletion of records is not a simple
task.
http://www.saif4u.webs.com
5
ii) Sequential File Organisation: Here records are kept either in ascending or
descending order. Here if we want a particular record, we have to read on the
record before acquiring or reaching the desired record. Ordering can be done
on the basis of one key field.
Ex: If we take the employee first in an office, the ordering can be done in
the ascending order of employee number. The records in the files are
stored on a magnetic tape.
a) Working with sequential file is simple.
b) Record can be accessed easily on the basis of key field (primary key).
c) Cost is minimized as only transaction files are resorted.
d) Making changes in the existing records is some what difficult job.
e) For addition or deletion of records is some file should be sorted.
ii) File sequential File Organisation: This File Organisation enables the user
to access file randomly. The index table is created on the disk at the same
time that the data is recorded on the disk. This Index table stores each
records key field and the address of the disk of that record.
iv) Random File Organisation: In this organization user can access any report in
the file. In this approach computer can directly locate the record without
searching or reading the previous records. In this organisation record is given a
particular number which is called as key number to reach directly for a
particular record. This key number is calculated using a HASH technique.
http://www.saif4u.webs.com
6
Advantages of DBMS
i) Data Redundancy
ii) Data control
iii) Data manipulation
iv) Excessive programming effort
v) Concurrent access and crash recovery
vi) Data integrity and security
vii) Data independence
http://www.saif4u.webs.com
7
type of transaction each and every user feels that data can be accessed
by only user at a time DBMS protect users from the effect of system
failure or crash recovery by creating a backup file to your original data.
vi) Data integrity and security: Database system can enforce integrity
constrains (primary key) on the data. It checks and has security that data
is visible to different classes of users by database administrators.
vii) Data independence: the main advantage of DBMS is that programs
will not be depending on the data. It uses a easy techniques to store and
retrive data efficiently from external storage devices.
Dis-Advantage of DBMS
i) Higher cost: The database system also involves higher data processing
cost. There is always increased hardware and software investment. So, a
lot an investment is needed for maintaining data bases.
ii) Lack of training: There is again lack of training people in the database
system. Database experts may be maintaining at higher cost.
iii) Data insecurity: The database must be properly maintained by the
authorized people. If they are not properly maintained there are chances
for opening, adding deleting the data. Thus, there is always a chance for
data insecurity.
iv) Data integration: Different department maintained data in different
files. It is difficult to ensure togetherness among the same data in all
departments. It is optimised for certain kind of organizational levels.
http://www.saif4u.webs.com
8
iii) Data: No database system can exist without data, data can be collected
and entered into the database in the from of tables.
http://www.saif4u.webs.com
9
APPLICATION PROGRAM
PRACTITIONER
APPLICATION PROGRAM
APPLICATION PROGRAM
USERS
DBMS
Client/Server Platform
Client: The client is the front end computer that interfaces with the user.
Server: The server is the back and machine and handles those parts of
the job which are common to making clients. Such as Database access
an update.
Database servers
A program running on server hardware to provide database services to
client machine.
Client server platform
A local area network consisting of client computers which receive services
from server computer.
Data sharing
The most significant difference b/w of file based system and a database
system is that data are shared.
There are 3 types of Data sharing:
i) Sharing Data b/w functional units: The term data sharing suggest that
people in different functional units use a common pool of data. Without
data sharing each group benefits only from its own data.
The effect of combining data into a database is synergistic i.e.
combined data are more valuable than the same of the data in separate
files. The concept of combing data for common use is known as data
integration.
ii) Sharing data b/w different levels of users: There are three different
levels of users.
a) Operation or electronic data processing
http://www.saif4u.webs.com
10
Executive DSS
Operations
EDP
iii) Data sharing b/w different locations: As the companies grow they
tend to open branch officers with there own data needs. Once
communication technology improved a serious study of distributed
database system being.
A distributed database system is made of several database
systems running at local sites connected by connection lines. For a
distributed database system to function effectively. Adequate
communication technology must be available and the DBMS in the
system must be able to communicate while interfering with the
communication facilities. The data resides at those places where
frequent access takes place. This approach improves cost effectiveness.
http://www.saif4u.webs.com
11
Functions of DBA
i) Database Design
ii) User training
iii) Database Security and Integrity
iv) Database System performance
http://www.saif4u.webs.com
12
who can diagnose and solve the problems. Problems are mainly involving in
hardware, physical arrangement of data and disk.
http://www.saif4u.webs.com
13
Database Development
Database development depends on 2 types of approaches:
i) Function oriented approach
ii) Data oriented approach
http://www.saif4u.webs.com
14
http://www.saif4u.webs.com
15
UNIT-2
Principles of conceptual Database Design
Reality: Reality involves a very large number of details.
Example for abstract is PERSON, which cannot be printed. This abstract instance
would be represented by an internal number. This number is called as
SURROGATE KEY meaning that it represents and uniquely identifies the
abstract object instance.
http://www.saif4u.webs.com
16
Basic Symbols:
Relationship: Attribute:
Multi valued
Attribute:
Derived Attribute:
http://www.saif4u.webs.com
17
E.R.Model Structure
ENTITY 1 ENTITY 2
REL
Entities: An entity is a person, place, and object. Event or concept in the user
environment about which the organisation wishes to maintain data some example
are:
Person: Employee, student, patient
Place: City, State, Country.
Object: Machine, Building, Automobile..
Entity Type: An entity type is a collection entity that share common properties or
characteristics. We use capital letters for names for entity.
Strong Entity: A strong entity type is one that exists independent of other
entity types. Instance of a strong entity type always have a unique identifier
(Primary Key)
Ex: EMPLOYEE (Emp_id, Emp_name, Sal)
Weak Entity: A weak entity is one that depends on their entity types i.e.
instances of an entity type does not have a Primary Key.
Ex: DEPENDENT (Dep_name, DOB)
Here, DEPENDENT is a entity name.
http://www.saif4u.webs.com
18
Attributes
An Attributes is a property or characteristics of an entity types that is of
interest to the organisation.
Ex: STUDENT (stud_id, stud_name, address..)
Here, STUDENT is a entity name.
Attributes are stud_id, stud_name, address.
Address
Composite attribute provides considerable flexibility to users, who can either refer
to the composite attribute as single unit or else to individual components of the
attribute.
Multivalued Attributes: A multivalued attributes is an attribute that may
take on more than one value for a given entity instance. We indicate a
multivalued attribute with an ellipse with double lines.
Ex: STUDENT (stud_name, stud_no, courseno, course_joined)
(Or)
EMPLOYEE (Emp_no, Emp_name, Sal, Addr, Skill)
http://www.saif4u.webs.com
19
Emp_nam sal
Emp_no
EMPNO
e
EMPLOYEE
Addr
ADDR SKILL
Identifier
It is an attribute (or combination of attributes) that uniquely identifies
individual instances of entity types. The identifier for the STUDENT entity type is
stud_no.
Relationship
http://www.saif4u.webs.com
20
Ex:
In above example EMPLOYEE and COURSE are two entities making relation
between them. Relationship between them. Relationship name is completes.
Degree of Relationship
The degree of a relationship is the number of entity type that participates in
that relationship. In above example relationship completes is of degree2. Since
there are two entity types: EMPLOYEE and COURSE.
http://www.saif4u.webs.com
21
One-one
One-to-many
Many to many
One-one
IS_ASSI
EMPLOYEE GNED PARKING PLACE
One to Many
PRODUCT IS_ASSI PRODUCT LINE
LINE GNED
It indicates that a product line may contain several products and ach
product belongs to only on product line.
Many to Many
STUDENT IS_ASSI
GNED
COURSE
It indicates that a student may register for more than one course and that
each course may have student registrants.
iii) Ternary Relationship: A Ternary relationship is simultaneous relationship
among the instance of 3 entity types.
PART
Shipping_mod
Unit_Cost
e
http://www.saif4u.webs.com
22
Cardinality Constraints
A cardinality constraint is a constraint that specifies is constraints that
specify the number of instances of entity B that may be associated with each
instance of Entity A. cardinality constraints normal specify the minimum and
maximum cardinality of one specifies mandatory participation.
Minimum Cardinality
The minimum number of instances of one entity that may be associated
with each instances of another entity.
Maximum Cardinality
The maximum number of instances of one entity that may be associated
with a single occurrence of another entity.
Degree of a relation
The number of attributes in relations is called the degree of the relation.
Null Values
The values given an attributes in a tuple. If the attribute is inapplicable or its
value is unknown.
Keys
Ex: WORKER(WORKER_ID,NAME,HOURLY_RATE,SKILL_TYPE,SUPV_ID)
http://www.saif4u.webs.com
23
Composite key
Ex:ASSIGNMENT(WORKER_ID,BLDG_ID,START_DATE,NUM_DAYS)
Candidate key
There may be more than one set of attributes that could be chosen as a key.
These are called candidate keys. When one of the candidate keys is selected as the
relation key. It may be primary key.
Foreign key
A set of attributes in one relation that is key in another relation. These are used
to indicate logical links between relations.
Ex: WORKER(WORKER_ID,NAME,HOURLY_RATE,SKILL_TYPE,SUPV_ID)
ASSIGNMENT(WORKER_ID,BLDG_ID,START_DATE,NUM_DAYS)
SKILL(SKILL_TYPE,BONUS_RATE,HOURS_PER_WEEK)
ASSIGNMENT table has two key attributes, both of them are underlined. This
means that WORKER_ID and BLDG_ID together are key for ASSIGNMENT.
SKILL_TYPE in the WORKER relation, WORKER_ID in ASSIGNMENT are
foreign keys.
FOREIGN key attributes need not have the same name as the key attributes to
which they correspond.
Integrity Constraints
A constraint is a rule that restricts the values in a database. Relational data
models include several constraints that are used to verity the validity of data in a
database as well as to add meaningful structure to the data.
Integrity constraints are of 2 types:
1) Entity Integrity
2) Functional Dependencies.
3) PRIMARY KEY
1) Entity Integrity: No key attributes of a row is NULL means value or data
should be given
http://www.saif4u.webs.com
24
2) Functional Dependencies: Every foreign key must either be null, or its value
must be the actual value of a key in another relation.
3) Primary Key: Every entity should have primary key.
Normal form: Applying simple rules on the relation to avoid redundancy and
delicacy.
Functional Dependencies: It is a constraint between two attributes or two sets of
attributes.
Ex: EMPLOYEE (Empno,ename,sal,design)
Here empno is a Primary key with the help of the Primary Key we can identify
the record uniquely. So, ename, sal, design of the employee are identified by an
attribute called Empno. So empno is called kwy attribute or determinant and rest
of the attributes are called non-key attributes. Therefore non-key attributes are
functionally depends on key attributes.
i.e. empno ename, sal, design
The attribute on the left hand side of the arrow is called key-attribute. The attribute
on the right side of the arrow is called Non-Key-Attribute. In general, any relation
or table R, the attribute B is functional dependency B on A is represented by arrow
as follow A B
Determinants
The attribute on the left hand side of the arrow in functional dependency
is called a determinant.
Ex: Empno ename, sal, design
Here empno is called determinant.
Candidate keys
A candidate key is an attribute, or combination of attributes, that
uniquely identifies a row in a relation.
Ex: consider the following relation
EMPLOYEE (empno,ename,sal,design,DOJ,Dno)
Here Empno, depno is called a candidate key which is a determinant
http://www.saif4u.webs.com
25
Above example is not in 1st Normal From. Because, BLDD_ID can have multiple
values: So,
http://www.saif4u.webs.com
26
http://www.saif4u.webs.com
27
WORKER
WORKER
Worker_ID Skill_Type Bonus_Rate
100 Electric 3.50
101 Plumbing 3.00
102 Electric 3.50
1 and 2 are F.Ds but 3 is not FD became Skill_type is not a Primary Key.
So to convert the above table in 3NF, decompose the relation in to
i) WORKER1 (Worker_id, Skill_Type)
ii) WORKER2 (Skill_Type, Bonus_Rate)
Here Skill_Type is WORKER1 relation is a foreign key and Skill_Type in
WORKER2 is a Primary Key.
http://www.saif4u.webs.com
28
Two language used with relational database are Relational Algebra and
Relation calculus.
Relation Algebra: A procedural language for manipulating relations.
Procedural language that provides a step by step method for solving problems.
Relational Algebra is also important because it contributes much of the
vocabulary and many of the basic relational data manipulation concepts that
are commonly found in database languages.
Relation Algebra operations manipulations relations. These operations use one
or two existing relations to create a new relation. This new relation may then
be used as input to a new relation. The creation of new relations from old ones
makes possible an infinite variety of data manipulations Relational Algebra
consists of the following Nine operations:
1) UNION
2) INTERSECTION
3) DIFFERENCE
4) PRODUCT
5) SELECT
6) PROJECT
7) JOIN
8) DIVIDE
9) ASSIGNMENT
The first four operations are taken from mathematical set theory.
Next four operations that apply specifically the relational data model.
The last operation_assignment is the standard computer language operation of
giving a name to a value. Symbol = is used to assign value to a variable.
SP_SUBORD
http://www.saif4u.webs.com
29
SP_Mar
Sal Per Id Sal Per_Name Manager_Id Office Com %
27 Terry 27 Chicago 15
44 C 27 Tokyo 12
35 D 27 Brussels 11
12 E 27 B.A 10
Salesperson= SP_SUBORD U SP_SUBORD
The salesperson relation contains all salesperson details. In this relation
columns will be same.
Result of UNION operation is..
SALESPERSON
http://www.saif4u.webs.com
30
This operation allows us to identify the rows that are common and two
relations. Let us take above tables SP_SUBD & SP_Mar. Intersection of these
two tables results in below table.
SP.SUBORD_Mar= SP_SUBORD n SP_MaR
SP_SUBORD_MAR
Salpers_id Salper_Name Manager_id Office Com %
44 C 27 Tokyo 12
35 D 27 Brussels 11
12 E 27 B.A 10
3) DIFFERENCE OPERATION
The difference operation (indicated by minus signs) allows us to
identify rows that are in one relation and in another. Suppose we are interested
in identifying the manager who is not subordinate to any other manager. Then
we take the difference between SP_MAR and SP_SUBORD.
SP_MAR_MAR: = (SP_MAR) _ (SP_SUBORD)
i.e. SP_MAR_MAR relation consists of all rows that in SP_MAR which are
not in SP_SUBORD. .ie.
SP_MAR_MAR
Saleper_Id Salpers_Name Manager_Id Ofice Com %
27 Terry 27 Chicago 15
4) PRODUCT
Its symbols is *. This operation creates the Cartesian product of two
relations.
Ex:
A B
X Y V Z
10 22 33 54
11 25 37 98
42 100
C: =A * B
X V W Z
10 22 33 54
http://www.saif4u.webs.com
31
10 22 37 98
10 22 42 100
11 25 33 54
11 25 37 98
11 25 42 100
C = A * B has 4 Columns
6 Rows i.e. 2 *3=6
5) SELECT OPERATION
The operation is used to create a relation from another relation by
selecting only those rows from the original relation that satisfied condition.
i.e. to retrieve selected rows from the table.
Query: Give all information or sales person who is in Tokyo office.
SP_Tokyo = SELECT (SALESPERSON: OFFICE = TOKYO)
City = Tokyo (OFFICE)
SP_TOKYO
6) PROJECT
This operation creates a relation by deleting unwanted columns from a
existing relation. Here SELECT operation required rows will be given,
PROJECT operation takes required columns will be given. () is the symbol
used for .
Ex: SP_Tokyo (SALPARS_NAME) Project
SALPERS_NAME
Masuj
Goro
http://www.saif4u.webs.com
32
Albert
7) JOIN
The operation joins together two tables on the basis of common values
in a column. The join operating is denoted by ><, is used to combine related
tuples from two relations in to single tuples. This operation allows to process
relationships among relations. Join connects relations on columns containing
comparable containing comparable information. There are 3 types of join.
i) Natural Join
ii) Theta Join
iii) Outer Join
8) DIVIDE
This operation creates a new relation by selecting the rows in one
relation that match every row in another relation.
Ex: A (X1, X2, X3..Xm, Y1, Y2, Y3.. Yn)
B (Y1, Y2, Y3...Yn)
9) ASSIGNMENT
Assignment operation gives names to a relation.
Ex: A: =SELECT (SALESPERSON: OFFICE = TOKYO)
:= is a symbol for ASSIGNMENT.
Unit-3
http://www.saif4u.webs.com
33
Data types: - SQL provides predefined data types and user defined data types in the
relational data types in the relational data base model. There are five data types.
1) CHAR (size): - this data type is used to store character strings values of fixed
length. The size in brackets determines the no., of characters the cell can hold.
The maximum number of characters in this data type can hold is 255 characters.
Oracle compares CHAR values using blank padded comparison, semantic i.e., if a
value that is inserted in a cell of CHAR data type is shorter then the size it is
defined for then it will be padded with spaces on the right until it reaches the size
character in length.
2) VARCHAR (size):- this data type is used to store variable length alpha numeric
data. The maximum data type can hold 2000 characters. One difference between
this data type and the CHAR data type is oracle compares VARCHAR values
http://www.saif4u.webs.com
34
using non-padded comparison semantics i.e., the inserted values will not be
padded with spaces.
3) NUMBER (p, s):- the number data type is used to store number (fixed, floating).
The numbers may be stored upto 38 digits of precision. The precision P
determines the maximum length of the data, where as the scale S determines the
number of places t the right of the decimal. If scale is omitted then the default is
zero.
4) Date: - this data type is used to represent data and time. The standard format is
DD-MM-YY.
5) Long: - this data type is used to store variable length character string screen
containing upto 2GB. Long data can be used to store arrays f binary data in ASCII
format.
Syntax: - create table <table name > (column name 1 data type (size), column name 2
data type (size), columnname3 data type (size));
Ex:-employee (emp no, emp name, adder, salary, dept)
To create table first set data types for each field.
Column name Data type Size
Emp no., Varchar 6
Emp name Varchar 20
http://www.saif4u.webs.com
35
adder Varchar 30
Salary Number 10,2
dept Varchar 10
Creation of a Table: -
Sql>create table employee (emp no varchar (6), empname varchar (20), addr varchar
(30), salary number(10, 2), dept varchar (10));
Insertion of data into tables:- INSERT COMMAND
Once a table is created, the next step is to load the table with data.
When inserting row of data into the table, the insert operation.
I. Creating a new row in the database table
II. Load the values passed into all the columns specified
Syntax: - insert into <table name> (column1, column2...) Values (exp1, exp2...);
Ex:- sql>insert into employee (emp no, emp name, addr, salary, dept) values (102,
pavani, hyd, 12000, accounts);
(Or)
Sql>Insert into employee values (&emp no,&emp name,&addr, &salary, &dept);
In insert command sentence the columns and values have a one to one relationship i.e.,
the first value described into the first column, the second value describe into the second
column and so on.
Data Manipulation:-
Simple query:-
A query involving only one data base table.
Viewing the data in the tables:-
Once data as been inserted into a table. The next most logical operation would be
view what has been interred. The select command is used.
http://www.saif4u.webs.com
36
SYNTAX:-
SELECT * from <table name >;
SELECT * from <table name> where <condition>;
Select Clauses:-
Identifies the columns desired in query. If the desired result contains more than
one column, the columns are all listed in the SELECT clause all separated by commas.
When data from all rows & columns from the table are to be viewed, we are
(*) char risk.
From clause:-from clause lists the existing tables referenced by the query.
Where clause:-It gives the condition for selected rows from identified tables. Where
clause is applied to each row, one by one any row not satisfying the where clause is
eliminated from consideration. These rows that satisfy the where clause are then
processed by the select clause.
Select command examples;-
Selecting all rows from a table.
Sql>Select * from Employee;
Selecting columns from a table.
Sql> Select Empno, Empname from Employee;
Sql> Select * from employee where DEPT = Accountants
Ex: -
1) Display rows from a table where salary between 1000 and 5000.
http://www.saif4u.webs.com
37
A table could hold duplicate rows. In such a case, to see only unique rows
use DISTINCT COMMAND
syntax : SELECT DISTINCT Column name1, Columnname2 from <table name>;
Ex: - sql>SELECT DISTINCT * from Employee;
Sorting Data in a Table:-
Oracle allows data form a table to be viewed on a sorted order. The
rows retrieved from the table will be sorted in either ascending or descending order
depending On the condition specified in the select sentence.
Syntax: - select * from <table name> ORDER BY column name1, column name2 (sort
order);
Query: -retrieve information of employee sorted on employee number field, in
descending order.
Sql>SELECT * FROM EMPLOYEE ORDER BY Empno desc;
In case there is no mention of the sort order, the oracle engine sorts in
ascending order by default.
Wild Card Characters: - Special symbols that stand for unspecified strings of
characters.
SQL has two wild card characters.
1 ) %( percent)
2) _ (under score). The underscore stands for exactly one specified character, the
percent stands for zero (or) more unspecified character.
The LIKE operator is used to compare character variables when wild card characters
are used.
Query: - Find all the employees whose name begins with A.
Select * from Employee where Empname like A%;
Data base Change Operations:-
SQL provides three data base change operations
INSERT, UPDATE and DELETE, to allow the addition of rows, the changing of values
in rows, and the deletion of rows, respectively, to or from a table.
INSERT: - Insert operation that causes rows to be added to a table,
Syntax: - INSERT into table name (column1, column2----------n)
VALUES (value1, value2----------value n);
OR
INSERT into table name values (&column1, &column2, ---------&column n);
Ex: -sql>Insert into Employee (Empno, Empname, Address, Phone no, ----)
VALUES (102, NEELIMA, UPPAL, HYD, 23456, ----);
UPDATE: - Operation that changes column values in rows. UPDATE Operations always
apply to all the rows that satisfy the WHERE clause in the UPDATE statement. TO
UUPDATE
*All the rows from a table
Or
*A select set of rows from a table.
http://www.saif4u.webs.com
38
http://www.saif4u.webs.com
39
In our example, since there are five columns in the worker table, and for
columns in ASSIGBEMNT there will be 9 columns in the new table, the total number of
rows in the new table is 133 rows i.e. 7x19=133.suppose. In worker table there are 7 rows
In ASSIGNEMNT table there are 19 rows If one table have m rows and
second table have n rows, then after joining, new table will have mxn rows.
After creating this gaintg table, the system applies the WHERE clause as before.
Each row of the relation created by the FROM clause is examined for conformity
to the WHERE clause. Those not satisfying the WHERE condition are eliminated
from consideration.
SUB QUERIES:
Sub query is a query with in a Query, can be placed with in the WHERE
clause of a Query, resulting in the expansion of the WHERE clauses capability.
Query:-What are the skill types of worker assigned to building 435?
Sql> SELECT SKILL TYPE FROM WORKER WHERE WORKER_ID IN
(Select worker ID FROM Assignment where BLDCT_ID=435);
2 Example:--
Retrieve all orders placed by a client named Rahul Desai from the sales order table
Table Name: - Sales order :( Order no, client no, Order date)
Sales order:
ORDERNO CLIENT NO ORDER DATE
019001 C00006 12-04-97
019002 C00002 25-12-97
019003 C00007 03-10-97
019004 C00005 18-01-97
019005 C00002 20-08-97
019006 C00007 12-01-97
http://www.saif4u.webs.com
40
Table: Client-master
Client no Name Bal/due
C00001 Ashok Mehra 500
C00002 Vishal Parikh 1000
C00003 Ajay Mehta 0
C00004 Rohith Roy 0
C00005 Nalini Deewan 0
C00006 Prem Iyer 0
C00007 Rahul Desai 0
Sql>SELECT * from sales-order WHERE client no= (Select client no from client master
WHERE name= rahul desai,
RESULT/OUTPUT:-
ORDER NO CLIENT NO ORDER DATE
019003 C00007 03-08-97
019006 C00007 12-01-97
Primary key:--
A primary key is one (or) more columns in a table used to uniquely identify
each row. A primary key coloum in a table as special attributes
1) It defines the columns as mandatory column i.e., the column cannot be left blank
2) The data across the column must be unique
A single column primary key is called a simple key a multi column primary
key is called a composite primary key. The only function of a primary key in a table used
to uniquely identified row. Only when a record cannot be uniquely identified using the
value in a single column a composite primary key will be defined.
Syntax:-Column name data type (size) PRIMARY KEY;
Sql>CREATE TABLE sales _order (order no varchar (6) PRIMARY KEY, orderdate
date, clientno varchar (10), salesman _no varchar (10));
Creation of Primary key as Composite key in the Table.
Syntax:-PRIMARY KEY (column name1, column name2)
Ex:-Create a table sales order details where there is a composite primary key on the
column order, product no
sql>Create table sales _ order(Orderno varchar (6), productno varchar(6), qty. ordered
number (8), product _rate number (8, 2), PRIMARY KEY (order no, product no));
Foreign Key:-
http://www.saif4u.webs.com
41
Sql>Select product no, sum (qty order) Total quality from sales Order group by
product no;
http://www.saif4u.webs.com
42
Output:-
ProductNo Total Quality
P0001 16
P0002 4
P0003 2
P0004 4
P0005 10
P0006 19
Having Clauses:-
The having clauses can be used with group by clause. Having on the
group by clause, which further filter the groups created by the group by clause.
Ex:-Retrieve the product no and total availability ordered for products p0001, p0004
from the sales-order table.
Sql>Select product-No, sum sales-(Qty-order) Total quantity from sales-order group
by product-no having productno = p0001 or productno = p0004,
Product No Total Quantity
P0001 16
P0002 4
Views:
To reduces redundant data to the minimum possible, oracle allows the create of
an object called a view.
The reasons for creating view sale:
1) When data security is required.
2) When data redundancy is to be kept to the minimum while maintaining data
security.
Creation of Views:-
CREATE VIEW<view name >AS
Select <colname1, colname2, -----from <table name>
Where column name=expression list;
Ex:-create a view the sales man _master for the sales department.
Sql>CREATE VIEW AS SELECT * from Salesdepartment;
Views can also be used for data manipulation (i.e. the user can perform the insert,
update and delete operations).
http://www.saif4u.webs.com
43
http://www.saif4u.webs.com
44
10) Function: This painter is used to develop user-defined functions which can be
used in Power Builder scripts.
11) Library: Library controls the management of applications, windows, and other
objects created using Power Builder.
12) User Object: This painter is used to create user objects-customized controls
(buttons, lists, and so on) that can be placed in windows.
13) Run: Pressing this button causes the current application to run.
14) Debug: The debug facility provides means of debugging applications.
2. IF-----ELSE:
Syntax: If<Conditional EXP>
<Statement block>
ELSE
<Statement block>
http://www.saif4u.webs.com
45
The key word AS signals the end of the parameter definitions and the
beginning of the procedure definition. Every thing after AS constitutes the executable
parts of the procedure.
UNIT-IV
http://www.saif4u.webs.com
46
Data dictionary
Physical storage:-
1) MAIN MEMORY 2) SECONDARY STORAGE
1) Main Memory:-It is a storage medium used for data that are available for user
operations. This is where the executing program resides. As data are required for the
program to execute its function, those data are transmitted from secondary storage to
http://www.saif4u.webs.com
47
main memory. In memory, storing the database is very difficult. So to store entire
storage secondary is required.
2) Secondary storage: - Secondary storage for storing database is in disk storage (hard
disk) and magnetic tapes. The entire database is stored in hard disk, when ever
required it sends to memory. The physically unit in which the disk drive contains one
disk pack or volume.
There are four factors that directly affect the speed with which data are transferred to
from disk storage.
1) Access motion time.
2) Head activation time.
3) Rotational delay
4) Data transfer rate.
1) Access Motion Time :-( A):- it is the time required to move the read/write heads
from their current position to new address. Where required data is stored.
2) Head activation time: - it is the time required to activate the head over the surface
where data transfer is to take place. This is used in performance calculations.
3) Rotational delay :-( R):- this is third timing factor. It denotes the amount of time
required for the desired block to rotate to the head. Rotational delay depends
upon two factors.
A) How fat the disk is rotating and
B) The location of the block to the read/write head at the time of its
activation.
4) Data transfer rate :-( D):- it refers to the amount of time requires to transfer data
from the disk to primary memory.
Data transfer time :-( T):- the expected time (T) to access a disk adder and transfer
a block of data is estimated as
T=A+R/2+L/D
A is the access motion time
R I the rotational delay
L is the length of the block in bytes
D is the data transfer data.
http://www.saif4u.webs.com
48
Here, the records are stored one after and accessed in the
same manner. In order to get a particular record all the previous records
must be read to access the required records. There is no logical order in this
method of file organization.
To reach the 12th number record, we should surpass first three records.
Example: - If we take the employee list in an office, the ordering can be done
in the ascending order of employer number. The records in this file are stored
on a magnetic tape.
http://www.saif4u.webs.com
49
Example: -
Look at the index, find the address and go directly to that record. Just
like a books index, which has different topics and their corresponding
page number.
Addition and deletion of records are more complex as they effect both
the index and file tables.
In this file organization user can access any record in the file.
In this approach computer can directly locate the record without searching or
reading the previous records. In this organization record is given a particular
number which is called as key number to reach directly for a particular
record. This key number is calculated using a hash technique.
http://www.saif4u.webs.com
50
Hash function: -
The work key rather freely to mean a data item whose value
uniquely identifies a record. This definition define a primary key. A secondary
key is one that identifies a set of records having the same value for the
http://www.saif4u.webs.com
51
2 Patton Auto 36 4
3 Forties Boat 24 0
4 Wood Auto 36 5
5 Cayman Home 36 7
6 Vance Auto 48 8
7 Costas Home 36 0
8 Ubu Auto 48 0
http://www.saif4u.webs.com
52
Responsibilities
http://www.saif4u.webs.com
53
DBA Goals:-
The main Goals of DBA are
1) Data Integrity: - The accuracy and consistency of data stored in the database
system.
2) Data Security: - Refers to protecting the database system from unauthorized use.
Database Integrity:-
Integrity control or constrains means restriction applied to a given set of data;
used to minimize data entry error.
ER-Model have constraints that apply to
1) Individual attributes 2) Relationship between two tables
1) Integrity constraints on SQL
2) Transaction processing
3) Concurrency control
http://www.saif4u.webs.com
54
Dead lock: - Two transactions are mutually excluded from the next record
required to complete their transaction; that status we called it as Deadlock.
http://www.saif4u.webs.com
55
T10
T9 T12
T11
Database security
Database security is generally easier to cope with an malicious
access to the database, which includes the following
1) Theft of information
2) Unauthorized modification of data.
3) Unauthorized destruction of data.
http://www.saif4u.webs.com
56
1) Authentication:-
a) First level of authentication is giving identity to the user by
Something the user knows, such as password
Something the user processes such as ID card
Physical representation of the user, such a finger print or voice print.
b) A password scheme limits unauthorized system access by creating a password
that is difficult to guess but still easy for the user to remember.
c) A passwords will be different for different user and different systems. So to
maintain all the passwords, it is advisable to appoint a password supervisor to
ensure that password parameters are satisfied. All the list of passwords will be
maintained by him. If any employee terminates or transfer to other functional area,
all the passwords will be changed by the supervisor.
d) For creating passwords one scheme can be used is a question and answer session
with user.
e) If the user unable to supply a valid password with in a set time or no; of trials, the
should automatically logoff users.
f) Unauthorized system access can be further controlled by allowing read only
functions.
To give this authorization to the users SQL have2 commands called GRANT and
REVOKE>
http://www.saif4u.webs.com
57
ENCRYPTION
The various authentication and authorization measures that are standard for
protecting access to databases may not be sufficient for highly sensitive data.
In such instance, it may be desirable to ENCRYPT the data.
ENCRYPT: - it means that to convert readable text to unreadable text by use of an
algorithm; this method is used to protect sensitive data.
Method of converting Encrypted data to Normal text we called it as Decipher or
Decryption
One method or scheme is called public key encryption. In this method, there are
two keys, a public key and a private key. Each user has a public key (Ei) and private
key (Pi). All the public keys are published. Each users private key is known only to
the user to whom the key belongs. If user wants to store encrypted data, he can
encrypts it using public key (Ei). Decryption requires the private key (Pi).
http://www.saif4u.webs.com
58
Database Recovery:-
Sources of failures: -
1) System errors: -the system has entered an undesirable state, such as deadlock,
which prevents the program from continuing with normal processing. This type of
failure may or may not result in corruption of data files.
2) Hardware failures: - two of the most common types of hardware failures are
disk failures and loss of transmission capability over a transmission link
3) Logical errors: - bad data or missing data are common conditions that may
interrupt the programs continuing with normal execution.
http://www.saif4u.webs.com
59
UNDO (Ti): - which restores the value of all data items updated by transaction (Ti)
to the old values.
REDO (Ti): - which sets the values of all data items updated by transaction (Ti) to
the new values.
These two operations are important in order to guarantee correct behaviour
even if a failure occurs during the recovery process.
UNIT-V
DATA BASE MANAGEMENT SYSTEMS
DISTRIBUTED DATABASE SYSTEMS
http://www.saif4u.webs.com
60
2. Allowing each site to store and maintain its own database allows
immediate and efficient access to data that are used most
frequently.
http://www.saif4u.webs.com
61
http://www.saif4u.webs.com
62
http://www.saif4u.webs.com
63
Suppose the relations R and S shown in figure below are stored at sites 1 and 2,
respectively. If we wish to respond to a query at site 1 which requires the computation:
JOIN(R, S),
We could transmit all of S from site 2 to site 1 and compute the join at site 1. This would
involve the transmission of all 24 values of S.
Another way would be to compute
T=R [A2]
At site 1; then send T (6 values) to site 2, and compute
Site 1 Site 2
R S
A1 A2 A2 A3 A4
1 3 3 13 16
1 4 3 14 16
1 6 7 13 17
2 3 10 14 16
2 6 10 15 17
3 7 11 15 16
3 8 11 15 16
3 9 12 15 16
1.T=PROJECT A2
(R:A2)=
3
4
6
7
http://www.saif4u.webs.com
64
8
9
2. U=JOIN (T,S)= A2 A3 A4
3 13 16
3 14 16
7 13 17
3.JOIN (R,U)= A1 A2 A3 A4
1 3 13 16
1 3 14 16
3 7 13 17
This example provides a basis for defining a semijion. The semijoin of R with S is
SEMIJION (R, S) =<A projection of those attributes of R that intersect those of S>,
which is simply that portion of R that joins with S.
Therefore, JOIN (R, S) =JOIN (R, (SEMIJOIN (R, S), S).
If R and S are at different sites, computing join (R, S) as shown previously saves
transmitting data whenever R and S do not join completely, as was demonstrated in
above figure.
Client/Server Systems:-
The term client/server (CS) is not new, since CS system involving multiple
computers connected in a network is a concept that has been around for some time.
Client: a computer or workstation attached to a network that is used to access network
resources.
Server: a computer that furnishes clients with services such as databases, connections to a
network, or large disk drives. Servers can be mainframes, minicomputers, large
workstations, or LAN devices. More than one server can be involved in providing
services to clients.
Figure below shows as CS system with two servers, a database server and a fax server.
Suppose that client A requires data contained in the database server. The user expresses
the data request in the form of a query (e.g., SQL) and transmits it to the database server.
The database server executes the query on its data from the database server, and the
database server may service several request in parallel.
Clients communicate with servers through an application program interface (API)
sometimes called middleware. That is, remote procedure calls and message exchanges are
handled by APIs. Effective APIs can facilitate the implementation of new applications by
accommodating different network protocols and operating systems. As CS technology
matures, API features will probably become part of operating systems.
Workstations
Client A Client
B
Client Client D
C
http://www.saif4u.webs.com
65
http://www.saif4u.webs.com
66
needs powerful capabilities for classifying and combining data, as well as an easy-to-use
query language.
http://www.saif4u.webs.com
67
http://www.saif4u.webs.com
68
Response-time requirements:-
A DBMS has to perform at an expected level to be valuable to users.
Unacceptable response time to user request will lead to frustration. Frustration will lead
users to purse other means of satisfying their information needs. So, response-time should
be speed.
Implementing Issues:-
1) Database administration:-
http://www.saif4u.webs.com
69
2) Database testing:-
Good testing procedures are needed to ensure that the database3 system
fulfills user requirements and operates without major problems. Testing is normally
focused on validating the following operations:
The loading of the database has been done without violating the
data integrity.
Null values.
Generation of test data that will check every possible undesired condition
has been shown to be an intractable problem.
Loading the database: - Often the data to be stored in the database already exist on some
computer based medium such as magnetic tape. If all the required data exist, and database
http://www.saif4u.webs.com
70
loading may simply involve reconstructing the existing data i.e., program can be written
that reads the old files and creates the structuring needed for the new ones. As time goes
on slowly change the old files to new files.
Database Maintenance:-
Managing resources (storage devices)
http://www.saif4u.webs.com
71
http://www.saif4u.webs.com