Professional Documents
Culture Documents
The transaction has the four properties. These are used to maintain
consistency in a database, before and after the transaction.
1.Atomicity
2.Consistency
3.Isolation
4.Durability
Atomicity
•It states that all operations of the transaction take place at once
if not, the transaction is aborted.
•There is no midway, i.e., the transaction cannot occur partially.
Each transaction is treated as one unit and either run to
completion or is not executed at all.
Atomicity involves the following two operations:
Abort: If a transaction aborts then all the changes
madearenotvisible.
Commit: If a transaction commits then all the changes made are visible.
Example: Let's assume that following transaction T consisting of T1 and T2. A
consists of Rs 600 and B consists of Rs 300. Transfer Rs 100 from account A to
account B.
In DBMS, schedules may have the following three different kinds of equivalence relations among them-
1. Result Equivalent Schedules-
• If any two schedules generate the same result after their execution,
then they are called as result equivalent schedules.
• This equivalence relation is considered of least significance.
• This is because some schedules might produce same results for some
set of values and different results for some other set of values.
2. Conflict Equivalent Schedules-
• If any two schedules satisfy the following two conditions, then they
are called as conflict equivalent schedules-
• The set of transactions present in both the schedules is same.
• The order of pairs of conflicting operations of both the schedules is
same.
3. View Equivalent Schedules-
What is Lock?
A lock is a variable associated with a data item that describes the status of
the item with respect to possible operations that can be applied to it.
Generally, there is one lock for each data item in the database.
Locks are used as a means of synchronizing the access by
concurrent transactions to the database item.
Types of Locks
• Binary Lock: This locking mechanism has two states or values: locked and
unlocked.
• Multi-mode locks: In this locking type each data item can be in any state:
Shared lock: It is also known as a Read-only lock. In a shared lock, the
data item can only read by the transaction. ...
Exclusive lock: In the exclusive lock, the data item can be both reads as
well as written by the transaction.
Two Phase locking protocol
To guarantee serializablity, we must follow some additional protocol concerning the
positioning of locking and unlocking operations in every transaction. This is where the
concept of Two Phase Locking(2-PL) comes in the picture, 2-PL ensures serializablity.
• Two Phase Locking –
A transaction is said to follow Two Phase Locking protocol if Locking and Unlocking can
be done in two phases.
Growing Phase: New locks on data items may be acquired but none can be released.
Shrinking Phase: Existing locks may be released but no new locks can be acquired.
The two-phase locking protocol divides the execution phase of the transaction into three parts.
-In the first part, when the execution of the transaction starts, it seeks permission for the lock it
requires.
-In the second part, the transaction acquires all the locks. The third phase is started as soon as the
transaction releases its first lock.
-In the third phase, the transaction cannot demand any new locks. It only releases the acquired locks.
In the below example, if lock conversion is allowed then the following phase can happen:
Upgrading of lock (from S(a) to X (a)) is allowed in growing phase.
Downgrading of lock (from X(a) to S(a)) must be done in shrinking phase.
Example:
The following way shows how unlocking and locking work with 2-
PL.
Transaction T1:
• Growing phase: from step 1-3
• Shrinking phase: from step 5-7
• Lock point: at 3
Transaction T2:
• Growing phase: from step 2-6
• Shrinking phase: from step 8-9
• Lock point: at 6
Lock Point:
The “Lock Point” is when all locks are held for the whole
transaction. Binds all of the data used in a transaction together.
It, therefore, prevents a transaction from being split into parts.
Deadlock and Its Prevention
• In a database, a deadlock is an unwanted situation in which two or more
transactions are waiting indefinitely for one another to give up locks. Deadlock is
said to be one of the most feared complications in DBMS as it brings the whole
system to a Halt.
• Example – let us understand the concept of Deadlock with an example :
Suppose, Transaction T1 holds a lock on some rows in the Students table and needs
to update some rows in the Grades table. Simultaneously, Transaction T2
holds locks on those very rows (Which T1 needs to update) in the Grades table but
needs to update the rows in the Student table held by Transaction T1.
• Now, the main problem arises. Transaction T1 will wait for transaction T2 to give up
lock, and similarly, transaction T2 will wait for transaction T1 to give up the lock. As
a consequence, All activity comes to a halt and remains at a standstill forever unless
the DBMS detects the deadlock and aborts one of the transactions.
Deadlock Avoidance –
- When a database is stuck in a deadlock, It is always better to avoid the deadlock rather
than restarting or aborting the database. Deadlock avoidance method is suitable for
smaller databases whereas deadlock prevention method is suitable for larger databases.
- One method of avoiding deadlock is using application-consistent logic. In the above given
example, Transactions that access Students and Grades should always access the tables in
the same order. In this way, in the scenario described above, Transaction T1 simply waits
for transaction T2 to release the lock on Grades before it begins. When transaction T2
releases the lock, Transaction T1 can proceed freely.
Another method for avoiding deadlock is to apply both row-level locking mechanism and
READ COMMITTED isolation level. However, It does not guarantee to remove deadlocks
completely.
Deadlock Detection –
When a transaction waits indefinitely to obtain a lock, The database management system should detect whether the transaction is involved in a deadlock or not .
• Physical integrity: Physical integrity is the protection of data’s wholeness and accuracy as it’s stored and retrieved.
When natural disasters strike, power goes out, or hackers disrupt database functions, physical integrity is
compromised. Human error, storage erosion, and a host of other issues can also make it impossible for data processing
managers, system programmers, applications programmers, and internal auditors to obtain accurate data.
• Logical integrity: Logical integrity keeps data unchanged as it’s used in different ways in a relational database. Logical
integrity protects data from human error and hackers as well, but in a much different way than physical integrity does.
There are four types of logical integrity.
• Entity integrity: Entity integrity relies on the creation of primary keys, or unique values that identify pieces of data, to
ensure that data isn’t listed more than once and that no field in a table is null. It’s a feature of relational systems which
store data in tables that can be linked and used in a variety of ways.
• Referential integrity: Referential integrity refers to the series of processes that make sure data is stored and used
uniformly. Rules embedded into the database’s structure about how foreign keys are used ensure that only
appropriate changes, additions, or deletions of data occur. Rules may include constraints that eliminate the entry of
duplicate data, guarantee that data is accurate, and/or disallow the entry of data that doesn’t apply.
• Domain integrity: Domain integrity is the collection of processes that ensure the accuracy of each piece of data in a
domain. In this context, a domain is a set of acceptable values that a column is allowed to contain. It can include
constraints and other measures that limit the format, type, and amount of data entered.
• User-defined integrity: User-defined integrity involves the rules and constraints created by the user to fit their
particular needs. Sometimes entity, referential, and domain integrity aren’t enough to safeguard data. Often, specific
business rules must be taken into account and incorporated into data integrity measures.
Authentication and Types
• Data authentication is the process of confirming the origin and
integrity of data. The term is typically related to communication,
messaging and integration. Data authentication has two
elements: authenticating that you're getting data from the correct
entity and validating the integrity of that data.
• 5 Common Authentication Types
-Password-based authentication. Passwords are the most
common methods of authentication
-Access Control
-Discretionary access control(DAC)
Authorization and its Forms and Control
operations
• It is a set of rules that can be used to determine which user has what type of access to which
portion of the DB.
• Forms
-READ
-INSERT
-UPDATE
-DELETE
• Control operations
-ADD
-DROP
-ALTER
-PROPAGATE ACCESS CONTROL
Encryption
• It is the process of encoding information. This process converts the
original representation of the information, known as plaintext, into an
alternative form known as ciphertext. Ideally, only authorized parties
can decipher a ciphertext back to plaintext and access the original
information.
• Ciphertext is encrypted text transformed from plaintext using an
encryption algorithm. Ciphertext can't be read until it has been
converted into plaintext (decrypted) with a key. The decryption cipher
is an algorithm that transforms the ciphertext back into plaintext.
Views
• A view is a means of providing a user with a personalized model of
the DB.
• It is a useful way of limiting user’s access to various portions of the
DB.
• By creating different views for different classes of users, a high degree
of access control is automatically attained.