0% found this document useful (0 votes)
40 views

UNIT-IV-MCA-305-ADVANCED DBMS

ADVANCED DBMS UNIT 4 NOTES

Uploaded by

bankeyaditya7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
40 views

UNIT-IV-MCA-305-ADVANCED DBMS

ADVANCED DBMS UNIT 4 NOTES

Uploaded by

bankeyaditya7
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 15

UNIT-IV

Active Database and Real Time Databases Triggers in SQL


• The database with a set of associated triggers is called Active Database. The
trigger is a set of SQL statements that live in system memory with unique
names. PL/SQL code is executed automatically in response to a database
event, typically DML. Like other stored procedures, triggers are stored in the
database.
• triggers are stored in the database separately from their associated tables.
• Triggers can be defined only on tables, not on views. However, triggers on
the base table(s) of a view are fired if an INSERT, UPDATE, or DELETE
statement is issued against a view.

• Triggers work in ECA Model. It has mainly three parts,


• Event: A change to a database that activates the trigger
• Condition: A trigger restriction specifies a boolean expression must be TRUE
for the trigger to fire
• Action: A procedure that is executed when the trigger is activated. Similar to
the stored procedure it contains PL/SQL statement as we discussed earlier.
A trigger can include SQL and PL/SQL statements to execute as a unit and can
invoke stored procedures. However, procedures and triggers differ in the way
that they are invoked. While a procedure is explicitly executed by a user,
application, or trigger, one or more triggers are implicitly fired (executed) by
Oracle when a triggering INSERT, UPDATE, or DELETE statement is issued, no
matter which user is connected or which application is being used.
• Triggers in SQL are a powerful feature that allows developers to
automate certain actions in response to specific events or changes
that occur within a database. A trigger is a set of SQL statements
executed automatically when a specified event occurs, such as the
insertion, deletion, or modification of data in a table. This can be
useful in a variety of scenarios, such as updating related data in
other tables when a record is modified or enforcing business rules
and constraints on data to ensure data integrity. In a typical
lifecycle, a Firebase Realtime Database function does the following:
• Waits for changes to a particular Realtime Database path.
• Triggers when an event occurs and performs its tasks.
• Receives a data object that contains a snapshot of the data stored
at that path.
• Triggers in sql can automatically update data in other tables when
changes are made to a specific table. For example, when an order is
placed, a trigger can update the inventory table to reflect the
decrease in stock.
Event Constraint and Action: ECA Rules
• An ECA rule has three parts: an event, a condition, and an action. The
semantics of an ECA rule are: when the event has been detected, evaluate the
condition, and if the condition is satisfied, execute the action.
• The semantics of an ECA rule is straightforward: when an event is detected,
evaluate the condition, and if the condition is true, then execute the action.
There are a number of reasons why the reactive behavior is abstracted to three
different parts.
• An Event-Condition-Action (ECA) rule performs actions in response to events
provided stated conditions hold. For example, in a database system an event
may be any update operation on the data, e.g. inserting a new tuple into a
table, and may lead to an action which is another update operation, e.g. the
deletion of another tuple in another table. This behaviour, whereby actions are
performed in response to events, is described as reactive behaviour.
• Triggers work in ECA Model. It has mainly three parts,
• Event: A change to a database that activates the trigger
• Condition: A trigger restriction specifies a boolean expression must be TRUE for
the trigger to fire
• Action: A procedure that is executed when the trigger is activated. Similar to
the stored procedure it contains PL/SQL statement as we discussed earlier.
Processing and Concurrency Control

• Concurrently control is a very important concept of DBMS which ensures the


simultaneous execution or manipulation of data by several processes or user
without resulting in data inconsistency. Concurrency Control deals with
interleaved execution of more than one transaction.
• A set of logically related operations is known as a transaction. The main
operations of a transaction are:
• Read(A): Read operations Read(A) or R(A) reads the value of A from the
database and stores it in a buffer in the main memory.
• Write (A): Write operation Write(A) or W(A) writes the value back to the
database from the buffer.
• Database has two important operations:
• Commit: After all instructions of a transaction are successfully executed, the
changes made by a transaction are made permanent in the database.
• Rollback: If a transaction is not able to execute all operations successfully, all
the changes made by a transaction are undone.
Concurrency means, that more than one transaction can work on a system.
The advantages of a concurrent system are:
• Waiting Time: It means if a process is in a ready state but still the process
does not get the system to get execute is called waiting time. So,
concurrency leads to less waiting time.
• Response Time: The time wasted in getting the response from the cpu for
the first time, is called response time. So, concurrency leads to less
Response Time.
• Resource Utilization: The amount of Resource utilization in a particular
system is called Resource Utilization. Multiple transactions can run parallel
in a system. So, concurrency leads to more Resource Utilization.
• Efficiency: The amount of output produced in comparison to given input is
called efficiency. So, Concurrency leads to more Efficiency.
Query, Recursive query processing
Query Processing (QP) has four main phases:
1. Decomposition (consisting of parsing and validation)
2.Optimization
3.Code generation
4.Execution.
Aims are to transform high-level query into RA query and check that query is
syntactically and semantically correct.
• Query Processing is the activity performed in extracting data from the
database. In query processing, it takes various steps for fetching the data from
the database. The steps involved are:

• Parsing and translation

• Optimization

• Evaluation
1.Parsing and Translation:-As query processing includes certain activities for
data retrieval. Initially, the given user queries get translated in high-level
database languages such as SQL. It gets translated into expressions that
can be further used at the physical level of the file system. After this, the
actual evaluation of the queries and a variety of query -optimizing
transformations and takes place. Thus before processing a query, a
computer system needs to translate the query into a human-readable and
understandable language.
• Optimization
• The cost of the query evaluation can vary for different types of queries. Although the system
is responsible for constructing the evaluation plan, the user does need not to write their
query efficiently.
• Usually, a database system generates an efficient query evaluation plan, which minimizes its
cost. This type of task performed by the database system and is known as Query
Optimization.
• For optimizing a query, the query optimizer should have an estimated cost analysis of each
operation. It is because the overall operation cost depends on the memory allocations to
several operations, execution costs, and so on.
• Evaluation
• In order to fully evaluate a query, the system needs to construct a query
evaluation plan.
• The annotations in the evaluation plan may refer to the algorithms to be used
for the particular index or the specific operations.
• Such relational algebra with annotations is referred to as Evaluation Primitives.
The evaluation primitives carry the instructions needed for the evaluation of
the operation.
• Thus, a query evaluation plan defines a sequence of primitive operations used
for evaluating a query. The query evaluation plan is also referred to as the
query execution plan.
• A query execution engine is responsible for generating the output of the given
query. It takes the query execution plan, executes it, and finally makes the
output for the user query.
Compensation and Databases Recovery
• Database Systems like any other computer system, are subject to failures
but the data stored in them must be available as and when required.
When a database fails it must possess the facilities for fast recovery. It
must also have atomicity i.e. either transactions are completed
successfully and committed (the effect is recorded permanently in the
database) or the transaction should have no effect on the database.
• There are mainly two types of recovery techniques used in DBMS
• Rollback/Undo Recovery Technique
• Commit/Redo Recovery Technique
• Rollback/Undo Recovery Technique:-
• The rollback/undo recovery technique is based on the principle of backing
out or undoing the effects of a transaction that has not been completed
successfully due to a system failure or error. This technique is
accomplished by undoing the changes made by the transaction using the
log records stored in the transaction log. The transaction log contains a
record of all the transactions that have been performed on the database.
The system uses the log records to undo the changes made by the failed
transaction and restore the database to its previous state.
• Commit/Redo Recovery Technique:-
• The commit/redo recovery technique is based on the principle of reapplying
the changes made by a transaction that has been completed successfully to
the database. This technique is accomplished by using the log records
stored in the transaction log to redo the changes made by the transaction
that was in progress at the time of the failure or error. The system uses the
log records to reapply the changes made by the transaction and restore the
database to its most recent consistent state.

• In addition to these two techniques, there is also a third technique


called checkpoint recovery.

• Checkpoint Recovery is a technique used to reduce the recovery time by


periodically saving the state of the database in a checkpoint file. In the
event of a failure, the system can use the checkpoint file to restore the
database to the most recent consistent state before the failure occurred,
rather than going through the entire log to recover the database.
Multi-level recovery.
• Transaction failure
• A transaction has to abort when it fails to execute or when
it reaches a point from where it can’t go any further. This is
called transaction failure where only a few transactions or
processes are hurt.
• Reasons for a transaction failure could be −
• Logical errors − Where a transaction cannot complete
because it has some code error or any internal error
condition.
• System errors − Where the database system itself
terminates an active transaction because the DBMS is not
able to execute it, or it has to stop because of some system
condition. For example, in case of deadlock or resource
unavailability, the system aborts an active transaction.
• System Crash
• There are problems − external to the system − that may cause the system
to stop abruptly and cause the system to crash. For example, interruptions
in power supply may cause the failure of underlying hardware or software
failure.
• Examples may include operating system errors.
• Disk Failure
• In early days of technology evolution, it was a common problem where
hard-disk drives or storage drives used to fail frequently.
• Disk failures include formation of bad sectors, unreachability to the disk,
disk head crash or any other failure, which destroys all or a part of disk
storage.

• Recovery and Atomicity


• When a system crashes, it may have several transactions being executed
and various files opened for them to modify the data items. Transactions
are made of various operations, which are atomic in nature. But according
to ACID properties of DBMS, atomicity of transactions as a whole must be
maintained, that is, either all the operations are executed or none.
• Log-based Recovery
• Log is a sequence of records, which maintains the records of actions
performed by a transaction. It is important that the logs are written prior
to the actual modification and stored on a stable storage media, which is
failsafe.
• Log-based recovery works as follows −
• The log file is kept on a stable storage media.
• When a transaction enters the system and starts execution, it writes a log
about it.

You might also like