Hindi
Hindi
To ensure accuracy, completeness and the integrity of data, database system maintains following properties of 1 A trigger is a set of SQL statements stored in the database catalog.
transaction. 2 A trigger is a set of actions that are run automatically when a specified change operation (SQL INSERT,
1. Atomicity: Atomicity property ensures that at the end of the transaction, either no changes have occurred to the UPDATE, DELETE or TRUNCATE statement) is performed on a specified table or view.
database or the database has been changed in a consistent manner. At the end of a transaction, the updates made 3 Definition: A trigger is, "a statement that is executed automatically by the system as a side effect of a modification
by the transaction will be accessible to other transactions and processes outside the transaction. to the database".
2. Consistency: Consistency property of transaction implies that if the database was in consistent state before the Concept of triggers
start of a transaction, then on termination of a transaction, it will also be in a consistent state. In other words, Data is a)To design a trigger mechanism, we must:
in a consistent state when a transaction starts and when it ends. 1. Specify the conditions under which the trigger is to be executed.
3. Isolation: Isolation property of transaction indicates that action performed by a transaction will be hidden from 2. Specify the actions to be taken when the trigger executes.
outside the transaction until the transaction terminates. Thus each transaction is unaware of other transactions b)A trigger is a special user-defined function that binds to a table.
executing concurrently in the system. To create a new trigger, we must define a trigger function first, and
4. Durability: Durability property of a transaction ensures that once a transaction completes successfully (commits), then bind this trigger function to a table.
the changes it has made to the database persist, even if there are system failures. c)The difference between a trigger and a user-defined function is
Q2 States of transaction with diagram: that a trigger is automatically invoked when an event occurs
whereas a stored procedure must be called explicitly.
1. Active State (Initial State): This is the initial state of transaction. A
transaction is active when it is executing. A transaction always starts
with active state. It remains in active state till all commands of that d)Triggering events can be insert, delete or update.
transaction are executed. e)Trigger can be set to fire BEFORE an event occur or AFTER an event occur or even we can bypass the event by
2. Partially Committed: When a transaction completes its last using the INSTEAD OF command.
statement (command), it enters in partially committed state. f)If we configured a trigger to fire BEFORE an INSERT or UPDATE, we will have the additional benefit of modifying
3. Failed: If the system decides that the normal execution of the the new data to be inserted or updated and even skipping the operation itself.
transaction can no longer proceed, then transaction is termed as g)There are two types of trigger i.e., Row Level Trigger and Statement Level trigger.
failed. If some failure occurs in active state or partially committed h)A row level trigger is fired for each affected row.
state, transaction enters in failed state. i)A statement level trigger is fired only once for a statement.
4. Committed: When the transaction completes its execution For example, consider the statement:
successfully it enters committed state from partially committed state. UPDATE account_current SET balance balance + 100 WHERE balance >
5. Aborted: To ensure the atomicity property, changes made by j)Suppose executing this statement may affect 20 rows. If a row level trigger is defined for the table, the trigger will
failed transaction are undone i.e. the transaction is rolled back. After be fired for each 20 updated rows. But if it was a statement level trigger, it would have fired only once.
rollback, that transaction enters in aborted state. When the Advantages of Using Triggers:
transaction is in failed state, it rollbacks that transaction and enters in 1. Triggers provide an alternative way to check the integrity of data.
aborted state. 2. Triggers can catch errors in business logic in the database layer.
3. SQL triggers provide an alternative way to run scheduled tasks. By using SQL triggers, you don't have to wait to
Q3 Difference between timestamping vs locking run the scheduled tasks because the triggers are invoked automatically before or after a change is made to the data
in the tables.
Sr.
Timestamping Locking 4. Triggers are very useful to audit the changes of data in tables.
No.
Disadvantages of Using SQL Triggers:
It is used to decide whether a transaction should wait or 1. SQL triggers only can provide an extended validation and they cannot replace all the validations. Some simple
1 It is used for concurrency control.
rollback.
validations have to be done in the application layer. For example, we can validate user's inputs in the client side by
2 It is used for deadlock prevention. It is used to improve performance. using JavaScript or in the server side using server-side scripting languages such as JSP, PHP, ASP.NET, Perl, etc.
A lock is a variable associated with a data item that 2. SQL triggers are invoked and executed invisible from the client applications; therefore, it is difficult to figure out
3 Timestamp is a unique identifier to identify a transaction. describes its status concerning possible operations what happen in the database layer.
applied. 3. Triggers may increase the overhead of the database server.
Timestamping methods assign timestamps to Locking methods prevent unserializable schedules Q5 Checkpoint:
4 transactions, enforcing serializability by ensuring that by stopping more than one transaction from When a system failure occurs, some transactions need to be redone and some need to be undone. Log record can
transaction timestamps match the schedule. accessing the same data elements. find out this. But for that we need to search the entire log.
Timestamping methods may cause more transactions to Locking methods avoid transaction abortion by • There are two major difficulties with this approach.
5 1. The search process is time consuming.
abort than a locking protocol. preventing potentially conflicting transactions.
2. Most of the transactions that will be redone have already written their updates into the database. Hence, it is
Advantages of Two-Tier Client/Server Structure: better to avoid such redo operations.
Q10) Advantage and disadvantages of single tier
Advantage of Single-Tier: 1)This structure is quite easy to maintain and modify. • To reduce these types of overheads, checkpoints are introduced. During the execution the system maintains the
1. The data is easily and quickly available since it is 2)The communication between the client and server in log, using immediate database or deferred database modification technique.
2. located in the same machine. the form of request response messages is quite fast. In addition, the system periodically performs checkpoints, which require following sequence of operations:
Disadvantage of Single-Tier: Disadvantage of Two-Tier Client/Server Architecture: 1. Output onto stable storage, all log records currently stored in main memory.
1. This architecture is completely not scalable. 1)If the client nodes are increased beyond capacity in the 2. Output to the disk, all modified buffer blocks.
2. Only one user can access the system at a given architecture, then the server is not able to handle the 3. Output onto stable storage, a log record <checkpoint>.
time through the local client. request overflow and performance of the system
degrades.
Q20)Shadow paging
Shadow paging is a recovery technique used in database systems to ensure data consistency and recoverability. It's
a copy-on-write approach that avoids in-place updates to database pages
Advantages of Shadow Paging:
Simplicity: It's a relatively simple technique to implement.
Increased Concurrency: Multiple transactions can be executed concurrently without interfering with each other.
Fast Recovery: In case of a system crash, recovery is straightforward as the database can be rolled back to the
Q 17) Recoverable Schedule state of the last committed transaction.
Reduced Write Amplification: By avoiding unnecessary writes to disk, shadow paging can improve performance.
1) In recoverability, there is need to address the effect of Disadvantages of Shadow Paging:
transaction failures or concurrently running transactions. Storage Overhead: It requires additional storage space to store shadow pages.
2) Once a transaction T is committed, it should never be Performance Overhead: Creating and managing shadow pages can introduce overhead, especially for frequent
necessary to rollbacks T. updates.
3) The schedules those meet this condition are called
recoverable schedules and those do not, are called non-
recoverable.
.
4) In other words, A recoverable schedule is one where for each pair of transactions T and T_{j} such that T_{2}
reads a data item previously written by T_{v} the commit operation of T_{8} appears before the commit operation of
T_{9} Otherwise, the schedule is non recoverable
Q18 Cascadless Schedule?
1) Even if a schedule is recoverable, to recover
correctly from the failure of a transaction Tj may
have to rollback the transaction.
2)Transaction T10 writes a value of A that is
read by transaction T_{11} Transaction T_{11}
writes a value A that is read by transaction T 12'
Suppose that at a point transaction T_{10} fails.
T_{10} must be rolled back. Since, T_{11}
dependent on T_{10} T_{11} must be rolled back. Since, is dependent on T 11' T_{12} must be rolled back.
3) This concept, in which a single transaction failure results in a series of transaction rollbacks, is called cascading
rollback.
4) A cascadeless schedule is one where, for each pair of transactions T, and T_{1} and Tj that Tj reads a data item
previously written by Tj, the commit operation of T_{i} appears before commit operation of Tj.