Beruflich Dokumente
Kultur Dokumente
2
.
2M
2M
2M
6M
6M
6M
Relational Algebra is a procedural language that can be used to tell the DBMS
how to build a new relation from one or more relations in the database and the
Relational Calculus is a non-procedural language that can be used to formulate
the definition of a relation in terms of one or more database relations.
1. Relational algebra operations manipulate some relations and provide
expressions in the form of queries where as relational calculus forms
queries on the basis of pairs of expressions.
2. RA have operator like join, union, intersection, division, difference,
projection, selection etc. whereas RC has tuples and domain oriented
expressions.
3. Expressive power of RA and RC are equivalent. This means any query
that could be expressed in RA could be expressed by formula in RC.
4. Relational algebra is easy to manipulate and understand than RC.
5. RA queries are more powerful than the RC.
6. RC will form WFFs where as RA does not form any formula.
7. RA evaluation of query depends on the order of operations and RC do not
depends on the order of operations
8. RA is domain independent where as RC is domain dependent
9. RA specifies operations performed on existing relation to obtain new
relations. In RC operations are performed on the relations in the form of
formulae.
3
.
A sub query can have only one column in the SELECT clause, unless
multiple columns are in the main query for the subquery to compare its
selected columns.
An ORDER BY cannot be used in a sub query, although the main query
can use an ORDER BY. The GROUP BY can be used to perform the same
function as the ORDER BY in a sub query.
Sub queries that return more than one row can only be used with multiple
value operators, such as the IN operator.
6M
Syntax :
CREATE OR REPLACE TRIGGER [ schema. ]
< trigger_name >
{ BEFORE, AFTER }
{ DELETE, INSERT, UPDATE [ OF column1, . . . ]
ON [schema.] < table_name >
[ REFERENCING { OLD AS old, NEW AS new} ]
[ FOR EACH ROW [ WHEN condition ] ]
DECLARE
<variable declarations>;
<constant declarations>;
BEGIN
< PL/SQL sub-program body >;
Exception
< exception PL/SQL block >;
End;
Example :
CREATE OR REPLACE TRIGGER t_Audit_trail
BEFORE DELETE OR UPDATE ON
6M
Normalization Rule
Normalization rule are divided into following normal form.
12M
1.
2.
3.
4.
101
Adam
11
order2
sale2
102
Alex
12
order3
sale3
103
Stuart
13
order4
sale4
In Customer table concatenation of Customer_id and Order_id is the primary key.
This table is in First Normal form but not in Second Normal form because there are
partial dependencies of columns on primary key. Customer_Name is only dependent
on customer_id, Order_name is dependent on Order_id and there is no link between
sale_detail and Customer_name.
To reduce Customer table to Second Normal form break the table into following
three different tables.
Customer_DetailTable :
customer_id Customer_Name
101
Adam
102
Alex
103
Stuart
Order_DetailTable :
Order_id Order_Name
10
Order1
11
Order2
12
Order3
13
Order4
Sale_DetailTable :
customer_id Order_id Sale_detail
101
10
sale1
101
11
sale2
102
12
sale3
103
13
sale4
Now all these three table comply with Second Normal form.
Third Normal Form (3NF)
Third Normal form applies that every non-prime attribute of table must be dependent
on primary key. The transitive functional dependency should be removed from the
table. The table must be in Second Normal form. For example, consider a table with
following fields.
Student_DetailTable :
Student_id Student_name DOB Street city State Zip
In this table Student_id is Primary key, but street, city and state depends upon Zip.
The dependency between zip and other fields is called transitive dependency. Hence
to apply 3NF, we need to move the street, city and state to new table, with Zip as
primary key.
New Student_DetailTable :
Student_id Student_name DOB Zip
Address Table :
Zip Street city state
The advantage of removing transtive dependency is,
Amount of data duplication is reduced.
Data integrity achieved.
Boyce and Codd Normal Form (BCNF)
Boyce and Codd Normal Form is a higher version of the Third Normal form. This
form deals with certain type of anamoly that is not handled by 3NF. A 3NF table
which does not have multiple overlapping candidate keys is said to be in BCNF.
For a table to be in BCNF, following conditions must be satisfied:
R must be in 3rd Normal Form
and, for each functional dependency ( X -> Y ), X should be a super Key.
12M
When the system is restarted after a crash, the recovery manager proceeds in three
phases,
12M
1. Analysis Phase
2. Redo Phase
3. Undo Phase
Analysis Phase has three main objectives.
It determines the point in the log at which to start the Redo pass.
It determines (a conservative superset of the) pages in the buffer pool that were
dirty at the time of the crash.
It identifies transactions that were active at the time of the crash and must
beundone.
The Analysis phase begins by examining the most recent begin checkpoint record,
whose LSN is denoted as C in Fig 1, and proceeds forward in the log until the last log
record.
The Redo phase follows Analysis and redoes all changes to any page that might have
been dirty at the time of the crash; this set of pages and the starting point for Redo (the
smallest recLSN of any dirty page) are determined during Analysis. The Undo phase
follows Redo and undoes the changes of all transactions that were active at the time of
the crash; again, this set of transactions is identified during the Analysis phase.
Redo Phase
During the Redo phase, ARIES reapplies the updates of all transactions, committed or
otherwise. Further, if a transaction was aborted before the crash and its updates were
undone, as indicated by CLRs, the actions described in the CLRs are also reapplied.
This repeating history paradigm distinguishes ARIES from other proposed
WALbased recovery algorithms and causes the database to be brought to the same
state that it was in at the time of the crash.
The Redo phase begins with the log record that has the smallest recLSN of all pages in
the dirty page table constructed by the Analysis pass because this log record identifies
the oldest update that may not have been written to disk prior to the crash. Starting
from this log record, Redo scans forward until the end of the log. For each redoable
log record (update or CLR) encountered, Redo checks whether the logged action must
be redone.
Undo Phase
The Undo phase, unlike the other two phases, scans backward from the end of the log.
The goal of this phase is to undo the actions of all transactions that were active at the
time of the crash, that is, to effectively abort them. This set of transactions is identified
in the transaction table constructed by the Analysis phase.
The Undo Algorithm
Undo begins with the transaction table constructed by the Analysis phase,
which identifies all transactions that were active at the time of the crash, and includes
the LSN of the most recent log record (the lastLSN field) for each such transaction.
Such transactions are called loser transactions. All actions of losers must be undone,
and further, these actions must be undone in the reverse of the order in which they
appear in the log.
7
12M
Deleting 19
Deleting 20
Deleting 20* is done with re-distribution. Notice how middle key is copied up.
3M
ACTIVE DATABASES
A trigger is a procedure that is automatically invoked by the DBMS in
response to specific changes to the database, and is typically specified by the DBA. A
database that has a set of associated triggers is called an active database. An active
database is a database that includes an event-driven architecture (often in the form of
ECA rules) which can respond to conditions both inside and outside the database
policy for creating new buckets and supports inserts and deletes efficiently without the
use of a directory.
4M
ISAM stands for Indexed Sequential Access Method, a method for indexing data for
fast retrieval. Fig 1 provides index page and fig 2 provides one level index structure.
Indexing permit access to selected records without searching the entire file.
Advantages:
Permits efficient and economic use of sequential processing technique when
the activity rate is high.
Permits quick access to records, in a relatively efficient way when this activity
is a fraction of the work load.
Disadvantages:
Slow retrieval, when compared to other methods.
Does not use the storage space efficiently.
Hardware and software used are relatively expensive.
Prepared by
Dr P.Kiran Sree, Professor, Dept of CSE, SVECW, BVRM