Rdbms Notes
Rdbms Notes
DATA
PROCESSING
OUTPUT DATA
http://www.saif4u.webs.com
http://www.saif4u.webs.com
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.
DISADVANTAGES OF FILE PROCESSING SYSTEMS:1. data Redundancy
2. Sharing of data is Poor
3. inconsistent data
4. enforcement of standards are poor
5. data dependency
6. inflexibility
http://www.saif4u.webs.com
http://www.saif4u.webs.com
5
ii) Sequential File Organisation: Here records are kept either in ascending or
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.
Ex:
INDEXTABLE
Key fields Index
no.
20
12
30
19
25
24
15
42
STUDINFO
Indexn Stno
o
12
20
19
30
24
25
42
15
sname %
A
B
C
E
67
98
88
90
a)
b)
c)
Advantages of DBMS
i)
ii)
iii)
iv)
v)
vi)
vii)
Data Redundancy
Data control
Data manipulation
Excessive programming effort
Concurrent access and crash recovery
Data integrity and security
Data independence
i)
ii)
iii)
iv)
v)
http://www.saif4u.webs.com
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)
vii)
Dis-Advantage of DBMS
i)
ii)
iii)
iv)
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.
Lack of training: There is again lack of training people in the database
system. Database experts may be maintaining at higher cost.
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.
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
ii)
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
PRACTITIONER
APPLICATION PROGRAM
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)
ii)
iii)
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
i)
http://www.saif4u.webs.com
10
b) Middle management or management information system
iii)
Executive
DSS
Middle manager
MIS
Operations
EDP
http://www.saif4u.webs.com
11
Functions of DBA
i) Database Design
ii) User training
iii) Database Security and Integrity
iv) Database System performance
i) Database Design: in this level there are 2 types of database designs.
Conceptual data base
Physical data base.
In conceptual database design identification of data, relationships that
exist b/w them of the value constrain that apply.
To carry out there designs DBA must include personnel who are
expert in design concepts. DBA occupies a strategic position in the definition
and enforcement of companies standards database design decisions are dept
in data dictionary.
ii) User training/Information centers: the DBA is responsibility for
educating users in the structure of the database and its access through
DBMS this will be done by training sessions through users manual
and companys information centers.
Information center is an area where users are provided with facilities to
do there own computing software packages should be provided as well
as training and simple programming services
iii) Data security integrity: The concept of combining and organisation
data into one place and accessing by all has both advantages and
disadvantages.
Data can be misused or damaged by users who d not have
original responsibility and authority over the data. DBA provides
procedure and controls to prevents the abuse of data i.e. retrieve only
access it means that users can check the data and second method is
access to the data base is ultimately controlled by a password
mechanism. DBA is responsible for assigning password
iv)
Data base system performance: In data system, data will be accessed
simultaneously by many users at a time in that case respond may be slow by a
server i.e. physical problem. DBA has a responsibility to include skilled persons
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.
ii)
iii)
iv)
v)
13
Database Development
i)
ii)
function
of an individual department. Basing this approach we have
method called system development life cycle. This procedure typically
consists of steps such as, feasibility study, requirements definition, system
design, programming and testing, review and maintenance.
ii) Data oriented approach: This approach focuses on the analysis of data
used by the functional areas (department). It has 2 advantages.
a) Data elements are a considerably more stable part of a system than the
function, of functional areas.
b) The proper structuring of a database schema requires sophisticated analysis
of classes of data item and their inter-relation.
14
ii)
iii)
iv)
v)
vi)
http://www.saif4u.webs.com
15
UNIT-2
Principles of conceptual Database Design
Reality: Reality involves a very large number of details.
Model: A model is a representation of reality that retains only selected details.
http://www.saif4u.webs.com
16
Weak Entity:
Relationship:
Attribute:
Multi valued
Attribute:
Derived Attribute:
http://www.saif4u.webs.com
17
E.R.Model Structure
Attribute Attribute
ENTITY 1
Attribute
REL
Attribute
ENTITY 2
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)
Here Employee is a Entity name.
Emp_id, Emp_name, Sal.. are attributes
Emp_id is a Primary Key.
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.
In naming attributes, we use an initial capital letter followed by lowercase letters.
If an attributes name consists of two words, we use an underscore character to
connect the words and we start each word with the capital letter.
Simple Attribute: A simple attribute is an attribute that cannot be broken
down into smaller components.
For example: All of the attributes associated with an entity AUTOMOBILE
are simple: vehicle_id, color, weight, power.)
Composite Attributes: A composite attributes is an attribute such address
can be broken down in to component parts.
Address
Str. Address
City
State
Postal_code
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)
In above example EMPLOYEE is a table/entity SKILL is attributes with so
many values.
http://www.saif4u.webs.com
19
Emp_no
EMPNO
Emp_nam
e
sal
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.
A composite identifier: it is an identifier that consists of a composite attributes.
Ex: FLIGHT (FLIGHT_number, FLIGHT_id, Date, No.of_passenger)
In the above example FLIGHT_Number_id combines to form an IDENTIFIER.
Relationship
A Relationship is an association among the instances of one or more entity
types that is of interest of the organization.
Relationship type is a meaningful association between two or three entities.
A relationship is denoted by a diamond symbol containing the name of the
relationship.
http://www.saif4u.webs.com
20
Ex:
Emp_id
Emp_name
EMPLOYEE
Courses_id
Course title
COURSE
COMPLET
E
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.
There are 3types of Relationships in E.R.Model:
i. UNARY (degree 1)
ii. BINARY (degree 2)
iii. TRINARY (degree3)
i) Unary Relationship: It is relationship between the instances of a single
entity type. Unary relationships are also called Recursive Relationship.
Ex:
PERSON
Is.Married
_to
EMPLOYEE
One-to-one
ii)
Manages
21
One-one
One-to-many
Many to many
One-one
IS_ASSI
GNED
EMPLOYEE
PARKING PLACE
PRODUCT LINE
IS_ASSI
GNED
It indicates that a product line may contain several products and ach
product belongs to only on product line.
Many to Many
STUDENT
iii)
COURSE
IS_ASSI
GNED
It indicates that a student may register for more than one course and that
each course may have student registrants.
Ternary Relationship: A Ternary relationship is simultaneous relationship
among the instance of 3 entity types.
PART
VENDOR
Supplies
Shipping_mod
e
http://www.saif4u.webs.com
WARE HOUSE
Unit_Cost
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)
In the above example worker_id attributes uniquely identifies an employee. We
can say that worker_id is a key in the WORKER relation.
http://www.saif4u.webs.com
23
Composite key
Ex:ASSIGNMENT(WORKER_ID,BLDG_ID,START_DATE,NUM_DAYS)
In the above table, keys consists of the WORKER_ID alone uniquely
identifies every row, but the two attributes together do provide the unique key. Such
a key is called composite key.
A key consisting of more than one attributes is called Composite key.
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
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.
2)
http://www.saif4u.webs.com
25
1235
1412
M.Faraday
C.Nemo
Electric
Plumbing
1311
1311
{312,515}
{312,460,435,513}
1311
C.Coulomb
Electric
1311
435
Above example is not in 1st Normal From. Because, BLDD_ID can have multiple
values: So,
Worker_ID
1235
1235
1412
1412
1412
NAME
M.Faraday
M.Faraday
C.Nemo
C.Nemo
C.Nemo
SKILL_TYPE
Electric
Electric
Plumbing
Plumbing
Plumbing
SUPV_ID
1311
1311
http://www.saif4u.webs.com
BLDG_ID
312
515
312
460
435
26
1412
C.Nemo
Plumbing
515
1311
C.Coulomb
Electric
435
Above table is in 1st Normal Form because there is not multivalued attributes.
Second Normal Form: A relation is in second normal form if it is in first
normal form and every non-key attributes is fully functionally dependent on the
primary key. A relation that is in first normal form will be in second normal form if
following condition applies:
i. The primary key should consists only on attribute
ii. Every non-key attribute is functionally dependents on the full set of
primary key attribute.
2)
Emp_ID
Course_Title
Name
Dept_Name
Salary
Date_Com
http://www.saif4u.webs.com
27
WORKER
Worker_ID
100
101
102
WORKER
Skill_Type
Electric
Plumbing
Electric
Bonus_Rate
3.50
3.00
3.50
1
2
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.
Boyce-code (BCNE): A relation in which every determinant is a candidate
key. When a relation has more than one candidate key.
Ex: Student_Advisor (SID,Major,Advisor,Maj_GPA)
FD: (SID,Major)
Advisor,Maj_GPA
(1)
FD: (Advisor)
Major
(2)
i.e Major is functionally dependent on Advisor above example is in 3NF. But
not in BCNF. Convert into BCNF
FD: Sid, Advisor
Major,Maj_GPA
FD: Advisor
Major
The determinant advisor becomes part of the composite Primary Key. The
attribute major, which is functionally dependent on Advisor, becomes a nonkey attribute.
In above relation is decompose the relation to eliminate the partial
functional dependency. To eliminate_partial functional dependency.
STUDENT_ADVISOR1 (SID, ADVISOR, MAJ_GPA)
STUDENT_ADVISOR2 (Advisor, Major).
4)
http://www.saif4u.webs.com
28
1)
2)
3)
4)
5)
6)
7)
8)
9)
1)
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:
UNION
INTERSECTION
DIFFERENCE
PRODUCT
SELECT
PROJECT
JOIN
DIVIDE
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.
UNION (U) OPERATION
This operation allows to combine the data from relations. The result of
this operation denoted by WUM, where W & M are two relations, is a relation
that included all tuples that are either in W or on M or in both W and M.
duplicate tuples are eliminated.
http://www.saif4u.webs.com
29
Salpers_id
Sales Name
Manager_id
Office
Com %
10
14
23
37
39
44
35
12
Jones
Masaji Mastu
Francois
A
B
C
D
E
27
44
35
12
44
27
27
27
Chicago
Tokyo
Brussels
B.A
Tokyo
Tokyo
Brussels
B.A
10
11
9
13
10
12
11
10
SP_Mar
Sal Per Id
Sal Per_Name Manager_Id Office
27
Terry
27
Chicago
44
C
27
Tokyo
35
D
27
Brussels
12
E
27
B.A
Salesperson= SP_SUBORD U
SP_SUBORD
The salesperson relation contains all salesperson details.
columns will be same.
Result of UNION operation is..
Com %
15
12
11
10
In this relation
SALESPERSON
SalPers_Id
10
14
23
37
39
27
44
35
12
2)
Sales_Name
Jones
Masaji Mastu
Francois
A
B
Terry
D
C
E
Manager_id
27
44
35
12
44
27
27
27
27
Office
Chicago
Tokyo
Brussels
B.A
Tokyo
Chicago
Tokyo
Brussels
B.A
Com %
10
11
9
13
10
15
12
11
10
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
44
C
35
D
12
E
3)
Office
Tokyo
Brussels
B.A
Com %
12
11
10
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
27
Terry
4)
Manager_id
27
27
27
Manager_Id
27
Ofice
Chicago
Com %
15
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
The product of A and B results C.
C: =A * B
X
10
V
22
W
33
http://www.saif4u.webs.com
Z
54
31
10
10
11
11
11
i.e
22
22
25
25
25
37
42
33
37
42
98
100
54
98
100
A has
2 Rows
2 Columns
B has 3 Rows
2 Columns
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
Salpers_id
14
39
44
Salpers_name
Masaj
B
C
Manager_id
44
44
22
Office
Tokyo
Tokyo
Tokyo
Com %
11
10
12
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
Unit-3
http://www.saif4u.webs.com
33
SEC
4565
323
100
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.
Rules of SQL syntax:1. An SQL statement starts with a verb. This verb may have additional nouns and
adjectives.
2. Each verb is followed by a number of clauses.
3. Each clause has 1 or more parameters.
4. A space separates clauses with in an SQL statement.
5. A comma separates parameters with in clauses.
6. A semi colon is used to terminate the SQL statement.
Ex: - create table employee (employee no., emp);
Here verb=create, noun/clause=table employee, parameter=employee no., emp
Creation of a table: - CREATE COMMAND
Table are defined in three steps
1. The name of the table is given.
2. Each column is defined including column constrains.
3. Table constrains are defined.
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
Salary
dept
Varchar
Number
Varchar
30
10,2
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.
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.
Renaming a table: - RENAME COMMAND
Syntax; - Rename<old table name> to <new table name>
Example: - sql>Rename employee to employee details
Destroying /deleting a table:- Drop Command
To destroy a table syntax is
Syntax; - DROP <Table name>
Example: - sql>DROP Employee;
Column details of a table creating:- DESCRIBE COMMAND
This command displays the column names, the data type and the special attributes
connected to the table.
Syntax: - Describe <table name>
Example: - sql> Describe employee;
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
Comparison Operators: - =,(not equals), <,>,<=,>=.
There are 6 comparison operator may be used to compare columns
with other columns.
SELECTING ROWS FROM TABLE USING COMPARISION OPERATORS.
1) Display ROWS FROM A TABLE WHOSE SALARY IS MORE THAN 10000.
Sql>SELECT * FROM EMPLOYEE WHERE SAL > 10000;
2) Display Rows from a table whose dept is commerce.
Sql>SELECT * FROM EMPLOYEE WHERE DEPT = COMMERCE;
3) Display rows from a table where salary is less than 5000;
Sql>SELECT * FROM EMPLOYEE WHERE sal < 5000;
Boolean Connections: - AND, OR, NOT.
These connections will be used to create compound conditions or to negate a
condition. Between can be used in a comparison of some value with two other first
smaller than the second. If the comparison value can be equal to either the smaller (or)
the larger (or) can be equal to any value in between.
Ex: 1) Display rows from a table where salary between 1000 and 5000.
SELECT * from employee WHERE SALARY BETWEEN 1000 AND 5000;
2) Display rows from a table whose employees are in commerce dept or are in
computer department.
Sql> SELECT * from employee WHERE dept = commerce or dept = computer;
Elimination of duplicates from the SELECT Statement: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.
UPDATING OF ALL ROWS:
http://www.saif4u.webs.com
38
Syntax: - update table name SET columnname1= Expression, column
name2=Expression2;
Ex:-Change Dept= sales where dept= sales1 of a employee table.
Sql>Update Employee SET DEPT= sales where dept =sales1;
Built in- Functions:
SQL provides fire statistical functions that examine a set if rows in a relation and
produce a single value. Functions are SUM, AVG, COUNT, MAX, and MIN.
Query:-What is the highest and lowest salary in employee table?
Sql> SELECT MAX (SALARY), MIN (SALARY) FROM EMP1;
The MAX and MIN functions operate on a single column in a relation. They
select the largest (or) the smallest value, respectively, to be found in that column.
COUNT (*):-Returns the number of rows in the table, including duplicates and those
with nulls.
Ex:- sql>SELECT COUNT (*) TOTALFROM EMP;
*Emp1 is table name
SUM:-Returns sum of values of n
Ex:-sql>SELECT SUM (SALARY) TOTAL AMOUNTFROM Emp1;
OUTPUT:-TOTAL AMOUNT
What is the average salary paying for employees?
AVG:-sql>SELECT AVG (SALARY) AVERAGE FROM EMP1;
Returns average value of n ignoring null values.
Multiple- Table Queries:-Some times data needed to solve the query from two tables.
This is accomplished through the relational calculus i.e., Join.
Ex:-1 Worker :-( worker ID, Name, Howdy-Rate, Skill type, SOPV-ID)
2 ASSIGNMENT (Worker ID, BLPG-ID, Start Data, NUM-Days)
In above example, there are two tables i.e. WORKER, ASSIGNMENT.
Now
1 QUERY:-What are the skill types of worker assigned to building 435?
This query is found in two in two tables WORKER and ASSIGNMENT. The
SQL solution requires the listing of both of these relations in the FROM clause.
Sql>SELECT SKILL_TYPE FROM WORKER, ASSIGNMENT WHERE WORKER.
WORKER ID = ASSIGNMENT. WORKER ID AND BLDG_ID=435;
2 QUERY:-Displays WORKER_ID, SUPV_ID, BLDG_ID from worker table and
ASSIGNMENT TABLE.
Sql>SELECT worker .WORKER_ID, SUPV_ID. WORKER_ID, ASSIGNEMNT,
BLDG_ID
FROM WORKER, ASSIGNMENT WHERE worker
.WORKER_ID=ASSIGNEMT, WORKER_ID
In this case, they are two tables in the clause. So, system creates the
Cartesian products of the rows in the tables. This means that one huge table is logically
created, consisting of all the columns form both tables, and pairing up every row in one
table with every two in the other table in the clause.
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
019001
019002
019003
019004
019005
019006
CLIENT NO
C00006
C00002
C00007
C00005
C00002
C00007
ORDER DATE
12-04-97
25-12-97
03-10-97
18-01-97
20-08-97
12-01-97
http://www.saif4u.webs.com
40
Table: Client-master
Client no
C00001
C00002
C00003
C00004
C00005
C00006
C00007
Name
Ashok Mehra
Vishal Parikh
Ajay Mehta
Rohith Roy
Nalini Deewan
Prem Iyer
Rahul Desai
Bal/due
500
1000
0
0
0
0
0
Sql>SELECT * from sales-order WHERE client no= (Select client no from client master
WHERE name= rahul desai,
RESULT/OUTPUT:ORDER NO
019003
019006
CLIENT NO
C00007
C00007
ORDER DATE
03-08-97
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
Foreign key represents relationship between foreign key is a column whose
values are derived from the primary key of some other table. The table in which the
foreign key is defined ids called a foreign table (or) detail table. The table that defines the
primary key and is referenced by the foreign key is called the primary table (or) master
table.
Syntax:-Column name data type (size) PRFERE NCES table name [(column table)]
Ex:-sql>Create table sales order (order No varchar (6) PRFERENCES sales order,
Product no varchar (6), Product rate number (6), Primary KEY (order no, product no));
The references key word points to the table sales order as the column order no as
its primary key column. Since no column is specified in the foreign key definition. Oracle
applies and automatic link to the primary key column i.e., order no of the table sales
order.
Grouping data from Tables:
There are the Group By and having clauses to retrieve data from tables. These
are parallel to the order by and where clause, expect that they act a record sets and not an
individual records.
GROUP BY CLAUSE:
The group by clause is another section of the select statement, this optional clause
tells to group rows based a values for specified columns.
Syntax:- select<select list> from<table name> Where <condition> Group by <grouping
list>
Ex:-retrieve the product number & total quality ordered for each product from the sales
order tables
Product No
P0001
P0004
P0006
P0002
P0005
P0003
P0001
P0006
P0004
P0006
Qty Ordered
10
3
7
4
10
2
6
4
1
8
Qty
10
3
7
4
10
2
6
4
1
8
Sql>Select product no, sum (qty order) Total quality from sales Order group by
product no;
http://www.saif4u.webs.com
42
Output:ProductNo
P0001
P0002
P0003
P0004
P0005
P0006
Total Quality
16
4
2
4
10
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).
Selecting a data set from a view:Once a view has been created, it can be queried exactly like a base table.
Ex:-SELECT column name1, columnname3, from view name;
http://www.saif4u.webs.com
43
systems. Power builder is a graphical application development environment which runs in
windows. It can be used to create application programs that interface with a large no.
different DBMS.
To create a application programs power builder provide a
number of painters, which are interactive sub programs that accomplish specific types of
functions needed for full application development. The process of developing
applications in power
Builder as Follows:
1) First, a database must be defined. This involves giving the database name,
defining tables with their columns, data types, keys, foreign keys.
2) After the database has been defined, we can start developing applications this is
done using power builders painters.
To develop each application we must perform three major steps.
1) Define the application. This is done with application painter.
2) Define the applications windows. This done with the window painter.
3) The application will act a data in the database. Therefore we must identify the
data needed for input, the data to changed, and the data which will be output.
This data identification is done through data windows, which are
defined in the data window painter.
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.
The system developer enters the desired painter by clicking on the
appropriate button. As the system enters the painter another bar of buttons, the painter
Bar, is displayed.
SERVER DATA MANIPULATION AND PROGRAMING:
SQL: - Server and oracle both provide control structures allowing for batch- style
programs in which sets (or) batches of statements executed with out interruption. These
control structures are part of SQL services control of flow and oracles PL/SQL
languages.
Control-of-flow (or) PL/SQL:
1) BEGIN----------END statements, which define blocks of SQL. Statements to be
treated as units for execution.
2) If ----------ELSE Statements for condition execution.
3) WHILE Statements for repeated orientation execution.
4) BREAK and CONTINUE Statements for early exit from WHILE loops.
5) DECLARE Statements allowing defining of local variables.
6) RETURN Statements
7) PRINT Statement provide for messages to be sent to the user.
8) Comments which allow internal documentation to be included with programs.
1. BEGIN------------END:-Condition (IF) and interactive (WHILE) Statements control
the execution of a single statement (or) a block of statements.
BEGIN
SQL Statement
----------------SQL Statement
END
A Statement block is either a single SQL Statement without delimiters (or) set of
two (or) more SQL Statements is limited by BEGIN-----------END.
2. IF-----ELSE:
Syntax: If<Conditional EXP>
<Statement block>
ELSE
<Statement block>
http://www.saif4u.webs.com
45
If can be used to determine conditions relative to the relation as a whole before
applying updater to the relation as a whole.
3. WHILE Statement:-A Statement which uses a condition to control the iterative
execution of a Statement block
Syntax:- WHILE <Conditional EXP>
<Statement block>
This statement causes the statement block to be repeatedly executed, as long as
the conditional evaluated to true.
Example:- WHILE( A> 0 )
BEGIN
STATEMENT1
STATEMENT2
END
4. BREAK AND CONTINUE: A KEYWORDwhich causes execution control to exit
from an iterative while loop. CONTINUE A KEYWORD which causes execution
control to return to the first statement in a WHILE LOOP.
STORED PROCEDURES:Stored Procedures SQL programs that are compiled the first
time they executed and then stored for later use. They provide a no. of advantages over
programs.
1) Procedures that have already compiled execute very fast.
2) They can receive and return parameter variables used to pass data into and out of
stored procedures.
Syntax:-CREATE PROCEDURE<Procedure name>AS
SELECT * FROM <Table name>
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
Request
Strategy selection
File manager
Translated request
Main Memory
Data dictionary
Disk storage
User data
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
Buffer Manag
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.
Disk pack is made up of a set of recording surface mounted on a shaft. Data
are recorded on tracks, which are circular recording positions found on each
surface. There may be hundred tracks on a single surface.
To read the data and save the data on each track of the surface, a set of
read/write heads, positioned on each surface of the disk. Set of such tracks is
called cylinder. The address of each record requires a cylinder no. A surface
number and block no.
http://www.saif4u.webs.com
48
File oriented system (or) file organization:The way of storing data (or) rewards in a file is called file organization. There are
four types of file organization. They are:1. Serial file organization: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.
It is simple and easy to understand
It is the cost effective method
It needs only one key record to locate
There is full utilization of storage space
This method is very slow as the entire file must be processed.
To reach the 12th number record, we should surpass first three records.
In this method updation i.e., addition (or) deletion of records is not a
simple task.
2. Sequential file organization: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.
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
3. Index sequential file organization:This file organization ennables the user to access file
randomly. The index table is created on the disk. This index table file
organization stores each records key field and the address of the disk of that
record.
Example: Key field
20
H.T.No
101
Name
A
Subject
RDBMS
30
102
ACCOUNT
15
103
BFS
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.
4. Random file organization: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
Dynamic hash functions: The static hash function is fairly simple. As the database grows,
however, the static hash function loses its appeal. A growing number of
collisions is assured, resulting in increased overhead to access records. One
strategy for dealing with this problem is to allocate estimated space for future
requirements at the outset; but this wastes storage space. Another scheme is to
allocate additional storage and reorganize the file as it grows.
A better approach is provided by the dynamic hash function. In
particular, the method we demonstrate here is called extendable hashing.
Extendable hashing splits and combines blocks as the database grows or
shrinks. This ensures efficient space utilization. Moreover, since reorganization
involves only one block at a time, the associated overhead is minimal.
Extendable hashing uses a hash function, h, that has the useful
characteristics of randomness and uniformity. It also (typically) uses a 32-bit
binary string in order to create and identify block indexes.
Secondary key access: 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
secondary key. Secondary keys play an important role in supporting the
information requirements of DBMS users.
Secondary key access is accomplished by establishing indexes
that traverse desired paths through the physical data records.
Example: - Query: Identify names of customer having 48-months loans. Figure
below is a sample instance, which shows how this information would be
provided through the use of linked lists. The primary key is CUSTOMER-NAME,
and the secondary key is LOAN-PERIOD. There are three financing periods for
loans: 24 months, 36 months and 48 months. Thus, the sets of records
associated with each of the three financing periods. Three pointers are thus
required to identify the beginning record in each set. These pointers are stored
separately from the data records themselves.
RELATIVE
ADDRESS
CUSTOMER
NAME
LOAN-TYPE
LOANPERIOD
Nixon
Auto
48
LOANPERIOD
POINTER
6
Patton
Auto
36
Forties
Boat
24
Wood
Auto
36
Cayman
Home
36
Vance
Auto
48
Costas
Home
36
Ubu
Auto
48
http://www.saif4u.webs.com
52
Data Administrator
(DA)
Database Administrator
(DBA)
http://www.saif4u.webs.com
53
First duty contralizing the database, because to eliminate local ownership
of data and to reduce redundancy
To maintain this database, users should have knowledge about database
concepts. So DBA should give training in database technology. How it can
make them more effective and efficient at their jobs.
So, DBA is responsible for educating users in the structure of the database
and technology used.
Training sessions should be given to users.
2) Planning, designing and implementing database systems : Planning for database design should be done by DBA with top management
cooperation
Conceptual design, physical designs are also taken care by DBA only.
For implementing the database certain skilled persons are to be required
3) Establishing standards and procedures:Effective database administration requires the establishment of uniform standards
and procedures
Their main purpose is to maintain control of data security and data
integrity.
Standards are mainly applicable in controlling the development and use of
database programming and operations. These standards are required to test
data to evaluate how a program handles both correct and erroneous data.
Procedures are created for error correction, check points and backup and
recovery.
http://www.saif4u.webs.com
54
1) Integrity Constraints: - A constraint is a rule that restricts that the vales in a
database. Relational data model includes several constraints that are used to verify the
validity of data in a database a well as to add meaningful structure to the data.
Integrity constraints are of two types:1) Entity Integrity:- no key attribute of a row is null means value or data should be
given
2) Referential Integrity: - every foreign key must either be null (or) its value must be
the
actual value of a key in another relation.
2)
Transaction control or processing: - transaction means a program unit
whose execution preserves the consistency (being in same result) of the database.
If the database is in consistent before a transaction executes then the database
should still be in a consistent state after its execution.
Atomic transaction:-a transaction in which all actions associated with the
transaction are executed to completion or none is performed.
Aborted transaction: - transaction that is canceled before changes are applied to
the database.
To support the transaction processing, a DBMS must maintain a transaction
record of every change made to the database, such record called a LOG.
LOG: - A record of all transactions and the corresponding changes to the
database.
If any changes are occurred on database i.e., updation has done, then
record resulting updates on the LOG.
If transaction fails, no need to write any thing on the LOG.
3)
Concurrent control:-a common way of preventing the concurrency
problem is through a simple locking policy.
LOCK prevent access to a database record by a second transaction unit the first
transaction has completed all of it actions.
If two or more users are accessing the database at the same time and
transaction are interleaved, undesirable results may occur.
When first user, performing first transaction on particular record, he lock the
record until hi transaction completes, when a record until I locked by one user, no
other user may ace it for update.
Dead lock: - Two transactions are mutually excluded from the next record
required to complete their transaction; that status we called it as Deadlock.
Deadlock detection: - A periodic checks by the DBMS to determine if the waiting
line for some records or resource exceeds a predetermined limit.
Another method of deadlock detection is by graph called wait for graph. A
deadlock exists in the system if and only if the wait for graph contains a cycle.
Periodically invoke an algorithm that searches for a cycle in the graph.
http://www.saif4u.webs.com
55
1) Transaction T9 is waiting for transaction T10 and T11.
2) Transaction T11 I waiting for transaction T10.
3) Transaction T10 I waiting for transaction T12.
Wait for graph with a cycle
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
So 3 ways have a database security.
1) Authentication 2) Authorization and views 3) Encryption
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.
Authorization and views: Creation of views
Giving authorized to access those views.
Views: - A restricted subset of a stored relation.
Types of Authorization on views:1) Read authorization, which allows reading but not modification of data.
2) Insert authorization, which allows insertion of new data, but not modification of
existing data.
3) Update authorization, which allows modifications, but not deletion of data.
4) Delete authorization, which allows deletion of data.
To give this authorization to the users SQL have2 commands called GRANT and
REVOKE>
GRANT statement is used to give authorization to the user.
Syntax: - GRANT <insert/alter/delete/select/update> on <view name> to user list>
Ex: - GRANT UPDATE on branch to U1, U2, U3.
In above example branch is the view name, U1, U2, U3 are the users name
REVOKE command is used to revoke authorization from the user.
Syntax: -REVOKE <command> on <view/table> from <user list>
Ex: -REVOKE UPDATE ON BRANCH FROM U1, U2 and U3.
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
Plaintext: - Which is readable text.
Cipher text: -Encrypted text
Ex: - SUCCESS
Becomes
TVDDFTT
But technique we used is very easy. Any one can decipher it.
ENCRPTION has many techniques.
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
NEED OF DISTRIBUTED DATABASES:A distributed database is not entirely stored in one central location but is
distributed among a network of location that are geographically separated and connected
by communication links. Each location has its own database and is also to access data
maintained at other locations.
1. Often organizations have branches or divisions in different
locations.
2. Allowing each site to store and maintain its own database allows
immediate and efficient access to data that are used most
frequently.
3. Distributed database can upgrade reliability. If one sites
computer fails, or if a communication link goes down, the rest of
the network can possibly continue functioning. Moreover, when
data are replicated at two or more sites, required data may still
be available from a site which is still operable.
4. Allowing local control over the data used most frequently at a
site can improve user satisfaction with the database system.
5. The advantage of data replication is the speed gained in
processing at sites where the duplicate data are maintained, as
well as providing backup copies of data in case of a system
failure another location.
http://www.saif4u.webs.com
61
62
the chance that a query can be executed without requiring data
transmission between stations. There is a corresponding cost and
time saving.
Database partitioning: - Efficiency may result from a strategy that implements a
partitioned database. With this approach, the database is distributed such that there is no
overlapping, or replication, of data maintained at the various locations. Since there is no
duplication of data, the costs associated with storing and maintaining redundant data are
avoided.
Because the distributed environment of the DDBMS allows the database to be
physically partitioned, data security may also be improved, particularly when the
partitioned segments have different security needs.
**Data fragmentation: - Data fragmentation applies to relation database systems. It refers
to ways in which relations can be subdivided and distributed among network sites. This is
an extension of the data-partitioning strategy, which is generally concerned with locating
entire relations (or files) from the database at various sites.
If a relation R is fragmented, it is divided into subsets (fragments) R1, R2,.,
Rn. The unions of these fragments reconstruct the original relation R. this fragmentation
can be horizontal, which assigns tuples to the various fragments; or it can be vertical,
where selected attributes are projected onto the various fragments.
Need of Fragmentation: - a database of airline reservations might be more effectively
used if database subsets are stored at the location of their respective flight origins.
Similarly, for a banking a
banking database, it may be useful to store database subsets at the location of the branch
where the respective accounts are located.
If fragmentation is allowed, a given relation is not necessarily stored in its
entirely at any single site. Its subsets may be distributed among several sites for
performance considerations. Moreover, these subset may be replicated.
Types of fragmentation:
Horizontal fragmentation: - Horizontal fragmentation is the division of tuples of a given
relation into fragments. Usually fragments are disjoint and may be replicated. In this way
replication is managed at the fragmentation level and not at the level of individual tuples.
Vertical fragmentation: - Vertical fragmentation is the division of the set of attributes of
an object into possibly overlapping subsets. Fragments are obtained by projecting the
original relation over each set of attributes.
***Distributed Query Processing:Some database system support relational databases whose parts are
physically separated. Different relations might reside at different sites, multiple copies of
a single relation can be distributed among several sites, or one relation might be
partitioned into subrelations and these subrelations distributed. In order to evaluate a
query posed at a given site, it may be necessary to transfer data between various sites.
The key consideration here is that the time required to process such a query will
largely be comprised of the time spent transmitting data between sites rather than the time
spent on retrieval from secondary storage or computation.
Semijoins:-
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
13
16
14
16
13
17
10
14
16
10
15
17
11
15
16
11
15
16
12
15
16
1.T=PROJECT
(R:A2)=
A2
3
4
6
7
http://www.saif4u.webs.com
64
8
9
2. U=JOIN (T,S)=
3.JOIN (R,U)=
A2
3
3
7
A1
1
1
3
A3
13
14
13
A2
3
3
7
A3
13
14
13
A4
16
16
17
A4
16
16
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
Database server
Fax server
Client
Client D
C
http://www.saif4u.webs.com
65
Determining
Application
Requirements:-Determining
the
information requirements to be supported by a database system
is a complex process that is entail in guiding the selection of a
DBMS. The analysis process can be simplified, however, if you
realize that user typically fall into two classes: regular, repetitive
users and occasional users.
66
needs powerful capabilities for classifying and combining data, as well as an easy-to-use
query language.
Database Recovery in DDMBS:The log plays a key role in failure recovery. The log is a history of all the
changes made to the database as well as the status of each transaction. It is important that
the data on the log not be lost or destroyed.log information is stored on a mythical stable
storage that survives all failures.
In distributed system, a log must be maintained at each site. In addition to
the previously specified information, the site log must record each message that it sends
and receives. In the distributed database environment there must be a means of detecting
failure and reestablishing the system status at time of failure when the system comes
backup.
DBMS functions and capabilities:To evaluate a DBMSs ability to service the organization information requirements,
following features required:1. The data dictionary/directory:An effective database system will allow growth and modification
in the database with compromising the integrity of its data. This feature is accomplished
by data dictionary. The data or information in the data dictionary is called metadata or
data about data. Other benefits provided by the DD/D includes
Physical storage structures can be changed without affecting the
programs that use the data.
Passwords and other security measures can be stored in DD/D.
Centralized data definition enables easy reporting on the status
of the database: whose is responsible for various data items,
what programs and users are accessing the data.
To yield these benefits, the DD/D includes the following features: A language for defining entries in the DD/D.
67
3. Query data manipulation and reporting capabilities: The DBMs ability to support report requirements, along with
users query and data manipulation needs, is the corner tone of todays management
system. The DBMS will provide a query language which is easy to learn and use.
4. Support of specialized programming requirements: Besides making it easier for the user to access
the database for information, the DBMS commonly provides
significant assistance to the application programmer as well such
tools screen, menu and report generators; application
generators; compilers; and soon.
5. Physical data organization: The firm acquiring a DBMS may not wish to
involve itself in the details of physical data organization. Instead,
it may guage the efficiency of a DBMS physical organization by
running Sample applications.
DBMS feature requirements:The function and capabilities provide a guide to determining key evaluation
criteria for choosing DBMS.CODASYL recommended some features for further analysis
in to the following categories:
http://www.saif4u.webs.com
68
1. Mandatory: - A DBMS feature that must be provided.
2. Important: - A DBMS feature that is not mandatory but makes the DBMS more
attractive.
3. Optional: - A DBMS feature that is of secondary importance.
4. Unnecesary: - A DBMS feature that contributes nothing to the value of the DBMS to
the firm.
5. Undesirable: -A DBMS feature that detracts from its value to the firm.
Analyzing Management Information Needs: Management Information: - Information to support company operations and decision
makers in pursuing of company goals.
So, management information needs of the firm should influence the choice of DBMS.
Characteristics of management information needs that may effect the choice of DBMS
include the following.
1. The potential need for information that may require data from
more than one application.
2. The way in which data need to be classified for decision making.
3. The current and expected volume of insertions and deletions
pertaining to existing and new data structures.
Determing application requirements: The application requirements can be done by the types of users.
1. Regular or repetitive user: - regular user is the one whose
applications may be described as production systems. The
requirements for these transactions driven system are planned in
advance and should support routine company operations.
2. Occasional users: - these users may require the greatest
flexibility. Since their requirements are often unforeseen. This
type of user needs powerful capabilities for classifying and
combining data, as well as an easy-to-use. Query language.
These users tend to require information for analysis and decision
making as apposed to support of routine operations.
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.
http://www.saif4u.webs.com
69
Servicing end-users requirements:-he is the responsible for
tracking the frequency of database use by end users and the
response times needed by their database application. He also
involved with satisfying the training needs of users.
Ensuring database security and integrity:-the DBA must maintain
controls to restrict the updating of the database to authorized
users.
Back up and recovery: - DBA has responsibility to look after the
database integrity and also when disk failure occurs.DBA devises
methods for restoring a complete and consistent database after
a failure. Restoration procedures involve utilities provided by the
DBMS as part of a larger recovery plan designed by the DBA.
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.
The application interface correctly with the database.
The performance of the system satisfies the requirements for
which the DBMS was acquired.
Another important testing is data testing
Values that have negative signs.
Invalid codes or keys.
Null values.
An unauthorized users attempt to change data.
Inappropriate units of measure.
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)
Backup and recovery
Managing changes to the database system
DBMS monitoring facilities
Managing resources:-When new data will be added to the
database, or some data may be deleted, and application will be
added and monitor such changes. Database resources such as
storage devices, indexes, and tables need to be checked. This
information will make decisions about upgrading resources as
well as forecasting future needs.
DBMS monitoring
functions:-
facilities:-following
http://www.saif4u.webs.com
are
the
monitoring
71
http://www.saif4u.webs.com