RDBMS Notes
RDBMS Notes
RDBMS Notes
INTRODUCTION:-
DATA
INPUT PROCESSING OUTPUT DATA
http://www.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.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.miteshk.webs.com
11
Functions of DBA
i) Database Design
ii) User training
iii) Database Security and Integrity
iv) Database System performance
http://www.miteshk.webs.com
12
http://www.miteshk.webs.com
13
Database Development
Database development depends on 2 types of approaches:
i) Function oriented approach
ii) Data oriented approach
http://www.miteshk.webs.com
14
http://www.miteshk.webs.com
15
UNIT-2
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.miteshk.webs.com
16
Basic Symbols:
Relationship: Attribute:
Multi valued
Attribute:
Derived Attribute:
http://www.miteshk.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.miteshk.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.miteshk.webs.com
19
sal
EMPNO
Emp_no Emp_nam
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.miteshk.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.
Manages
PERSON EMPLOYEE
Is.Married
_to
http://www.miteshk.webs.com
21
One-one
IS_ASSI
EMPLOYEE GNED PARKING PLACE
One to Many
PRODUCT IS_ASSI PRODUCT LINE
GNED
LINE
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 COURSE
GNED
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.miteshk.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.miteshk.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
http://www.miteshk.webs.com
24
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.miteshk.webs.com
25
Above example is not in 1st Normal From. Because, BLDD_ID can have multiple
values: So,
http://www.miteshk.webs.com
26
http://www.miteshk.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.D’s 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.miteshk.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.miteshk.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.miteshk.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
10 22 37 98
http://www.miteshk.webs.com
31
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
Albert
http://www.miteshk.webs.com
32
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
Data manipulation in data base
Introductions:
http://www.miteshk.webs.com
33
All organizations need to collect process and store data for its human,
financial, material needs.
For example:- an organization could store information for pay role, accounts receivable
and payable, sales receivable and forecast or design and manufacturing.
Table or entity: - to represent this information one can use DBMS modeling. In a DBMS
a group of interest to an organization is called an entity. Entity information is stored in an
object called table. For example: - client is considered as an entity. Information about the
client entity can be stored in a client master table. A table is really a two dimensional
matrix that consists of rows and columns.
Attributes/columns/fields: - each entity can have a number of characteristics. A client
can have characteristics like name, address, telephone number, fax number, balance due
etc., the characteristics of an entity are called an attribute. The values for this
characteristics are called attribute values. When entity information is stored in a table, the
attributes associated with the entity are stored in the table columns or table fields.
Example: - clients (name, address, telephone no., fax no., balance due)
Here entity : clients
Attribute: Name,
Tuple/record/row: -An organization will deal with many clients and the same
information must be recorded for each clients. Multiple fields paced in a horizontal plane
is called a record/ row / tuple.
NAME ADDRESS TELEPHONE FAX NO., BALANCE
DUE
A HYD 2345 333 1000
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
using non-padded comparison semantics i.e., the inserted values will not be
padded with spaces.
http://www.miteshk.webs.com
34
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
adder Varchar 30
Salary Number 10,2
dept Varchar 10
http://www.miteshk.webs.com
35
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.
SYNTAX:-
SELECT * from <table name >;
SELECT * from <table name> where <condition>;
http://www.miteshk.webs.com
36
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.miteshk.webs.com
37
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.miteshk.webs.com
38
http://www.miteshk.webs.com
39
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
Table: Client-master
Client no Name Bal/due
http://www.miteshk.webs.com
40
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:-
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
http://www.miteshk.webs.com
41
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
Sql>Select product no, sum (qty order) “Total quality” from sales Order group by
product no;
Output:-
ProductNo Total Quality
http://www.miteshk.webs.com
42
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.miteshk.webs.com
43
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 builder’s painters.
http://www.miteshk.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.miteshk.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.miteshk.webs.com
46
Data dictionary
Disk storage
User data
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.miteshk.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.miteshk.webs.com
48
http://www.miteshk.webs.com
49
20 101 A RDBMS
30 102 B ACCOUNT
15 103 C BFS
Hash function: -
The use of hashing is a method of record addressing that eliminates the need for
maintaining and searching indexes. There are important application whose predominant need is for
direct access of records, whose services could be encumbered by the use of indexing methods. The
basic idea is that of trading the time and effort associated with storing, maintaining, and searching
an index for the time required for the central processing unit (CPU) to execute a hashing algorithm,
which generates the record address. The hashing algorithm is a procedure for calculating a record
address from some field in the record, usually the key.
http://www.miteshk.webs.com
50
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.
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.miteshk.webs.com
51
Responsibilities
http://www.miteshk.webs.com
52
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
http://www.miteshk.webs.com
53
3) Concurrency control
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.miteshk.webs.com
54
T10
T9 T12
T11
Database security
Database security is generally easier to cope with an malicious
access to the database, which includes the following
http://www.miteshk.webs.com
55
1) Theft of information
2) Unauthorized modification of data.
3) Unauthorized destruction of data.
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.
To give this authorization to the users SQL have2 commands called GRANT and
REVOKE>
http://www.miteshk.webs.com
56
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 user’s 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.miteshk.webs.com
57
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.miteshk.webs.com
58
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.
http://www.miteshk.webs.com
59
UNIT-V
DATA BASE MANAGEMENT SYSTEMS
DISTRIBUTED DATABASE SYSTEMS
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.miteshk.webs.com
60
Data replication: - Data replication occurs if the system maintains several identical
copies of a relation, R, with each copy being stored at a different site. Typically
replication is introduced to increase the availability of the system: when a copy is
unavailable due to site failure(s), it should be possible to access another copy.
Replication can also improve performance under routine conditions, since transactions
have a greater probability of finding a copy locally.
The advantages of replication are:
1. If one of the stations containing relation R fails, the relation can be retrieved
from another site, and the system may continue any processing involving R. thus,
database availability is enhanced.
2. If most accesses to R only involve a read of the relation, then several sites can
process queries involving r concurrently. The more copies of R there are
throughout the network, the better the chance that a query can be executed
without requiring data transmission between stations. There is a corresponding
cost and time saving.
http://www.miteshk.webs.com
61
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 it’s
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:-
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
http://www.miteshk.webs.com
62
3 9 12 15 16
1.T=PROJECT A2
(R:A2)=
3
4
6
7
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.
http://www.miteshk.webs.com
63
Client Client D
C
http://www.miteshk.webs.com
64
http://www.miteshk.webs.com
65
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.
http://www.miteshk.webs.com
66
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.miteshk.webs.com
67
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.
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
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
http://www.miteshk.webs.com
68
http://www.miteshk.webs.com