DBMS-mod 1,2,3,4
DBMS-mod 1,2,3,4
Module-1
→Advantages of a DBMS
-Controls database redundancy: It can control data redundancy because it stores all the
data in one single database file and that recorded data is placed in the database.
-Data sharing: , the authorized users of an organization can share the data among multiple
users.
-Easily Maintenance: It can be easily maintainable due to the centralized nature of the
database system.
-Reduce time: It reduces development time and maintenance need.
-Backup: It provides backup and recovery subsystems which create automatic backup of
data from hardware and software failures and restores the data if required.
-multiple user interface: It provides different types of user interfaces like graphical user
interfaces, application program interfaces
-data integrity and security.
-data administration.
→Disadvantages of a DBMS
-Cost of Hardware and Software: It requires a high speed of data processor and large
memory size to run DBMS software.
-Size: It occupies a large space of disks and large memory to run them efficiently.
-Complexity: Database system creates additional complexity and requirements.
-Higher impact of failure: Failure is highly impacted the database because in most of the
organization, all the data stored in a single database and if the database is damaged due to
electric failure or database corruption then the data may be lost forever.
-Low performance.
-High maintenance cost.
#History of DBMS
-Charles Bachman was the first person to develop the Integrated Data Store (IDS) which was based
on network data model.
-It was developed in early 1960’s.
-In the late 1960’s, IBM (International Business Machines Corporation) developed the Integrated
Management Systems which is the standard database system used till date in many places.
-It was developed based on the hierarchical database model.
-t was during the year 1970 that the relational database model was developed by Edgar Codd. Many
of the database models we use today are relational based.
-Later during the same decade (1980’s), IBM developed the Structured Query Language (SQL) as a
part of R project.
-It was declared as a standard language for the queries by ISO and ANSI.
It doesn’t provide backup and recovery of data It provides backup and recovery of data even
if it is lost. if it is lost.
Only one user can access data at a time Multiple users can access data at a time.
The user has to write procedures for managing The user not required to write procedures
databases
The file system approach has a simple structure. The database structure is complex to design
*The Relational Model:-The relational model represents how data is stored in Relational
Databases.
-A relational database stores data in the form of relations (tables).
-A relation schema represents the name of the relation with its attributes. e.g.; STUDENT
(ROLL_NO, NAME, ADDRESS, PHONE, and AGE) is the relation schema for STUDENT. If a
schema has more than 1 relation, it is called Relational Schema.
-Attributes are the properties that define a relation. e.g.; ROLL_NO, NAME
-Consider a relation STUDENT with attributes ROLL_NO, NAME, ADDRESS, PHONE, and AGE
shown in Table .
-A description of data in terms of a data model
is called a schema.
-Each row in the relation is known as a tuple.
The above relation contains 4 tuples,
one of which is shown as:
●
● Or
*Data Independence:-Data independence is achieved through the use of the three levels
of data abstraction.
-It is the ability to modify the schema without affecting
the programs and the applications to be written. Or
It is the ability to modify the schema at one level of the
database system without altering the schema at the next
higher level.
-There are two types of data independence they are;
1.Physical data independence:-It is the capacity to
change the internal schema without having the
change in conceptual schema.
-If we do any changes in the storage size of the
database system server, then the Conceptual
structure of the database will not be affected.
-Physical data independence is used to separate conceptual levels from the internal levels.
-Physical data independence occurs at the logical interface level.
2.Logical data Independence:-Capacity to change the conceptual schema without having to
change external schema.
-Logical data independence is used to separate the external level from the conceptual
view.
-If we do any changes in the conceptual view of the data, then the user view of the data
would not be affected.
-Logical data independence occurs at the user interface level.
*Structure of a DBMS:-
-The figure shows the structure of a typical DBMS based on the relational data model.
-The DBMS accepts SQL commands generated from a variety of user interfaces,produces
● query evaluation plans
● executes plans against the database and
● Returns the answers
->fig explain
-Here we can notice that queries from variety of user interfaces are received by the dbms in
the form of sql commands.
-Query evaluation engine generates the query evaluation plan then it execute the query
evaluation plan against the database and after the execution it return the result back to the
user.
-Actually query evaluation plan is generated by query evaluation engine by using this four
modules ( plan executer ,parser,operator evaluation ,optimizer)
-initially sql commands are received by the parser then the parser break the query into
tokens and the it checks the query is in tactically and semantically correct or not.
-If the query is correct then it is converted into an algebraic expression.
-until this algebraic expression is passed as the input to the operator evaluator.
-Know the operator evaluator module evaluate the operators in the algebraic expression
using several techniques such as indexing techniques etc..
-And then set of possible query evaluation plan are generated for executing the sql query.
-then all this alternative query evaluation plans are given as the input to the optimizer.
-Know the optimizer module chooses the optimized query evaluation plan from the set of
alternative plans in order to execute the query most effectively
-then this optimized plan is executed by the plan executed module.
-during the execution of the query evaluation plan the rule of file access methods buffer
manager and disk space manager is very important.
-File and access methods provide the abstraction of file structure stored in the database and
it creates indexes of the file inorder to access the deserved file very quickly.
-Buffer manager is used to fetching there data from disk into main memory and also it is
used to decide what data to be kept in the cache memory.
-Then disk space manager is used to manage the space on the disk by providing empty
space for new request and deleting space for lot of existing files when ever they are
deleted by the users
-Then the translation manager and lock manager used to inputs concurrency control
because the data stored in database can be accessed by multiple user at the same time,
thats why this tranation manager and lock manager are used to inputs concurrency control.
-Recovery manager maintains a log that is used to restore the system to a consistent state
even after crash occurrence in the system or in the database.
-System catalolg which is also called data dictionary, it is usually stored the part of
database and it is used to store metadata information, that is it contain the discretion of all
the tables, views,datafiles and indexes which are stored in the database
Or
#Introduction to Database Design:-Database design can be generally defined as
a collection of tasks or processes that enhance the designing, development,
implementation, and maintenance of enterprise data management system.
-Properly designed database are easy to maintain, improves data consistency and are cost
effective in terms of disk storage space.
-The database designer decides how the data elements correlate and what data must be
stored.
-The main objectives of database design in DBMS are to produce logical and physical designs
models of the proposed database system.
-The logical model concentrates on the data requirements and the data to be stored
independent of physical considerations. It does not concern itself with how the data will be
stored or where it will be stored physically.
-The physical data design model involves translating the logical DB design of the database
onto physical media using hardware resources and software systems such as database
management systems (DBMS).
→Major Steps in Database Design/database design process can be divided into six steps
they are;
1.Requirements Analysis:-The very first step in designing a database application
-Talk to the potential users and Understand what data is to be stored, and what operations
and requirements are needed.
2.Conceptual Database Design:-Develop a high-level description of the data and constraints
(we will use the ER data model).
3.Logical Database Design:-Convert the conceptual model to a schema in the chosen data
model of the DBMS. For a relational database, this means converting the conceptual to a
relational schema (logical schema).
4. Schema Refinement: Look for potential problems in the original choice of schema and try
to redesign.
5. Physical Database Design: Direct the DBMS into choice of underlying data layout (e.g.,
indexes and clustering) in hopes of optimizing the performance.
6. Applications and Security Design: How will the underlying database interact with
surrounding applications.
↖️
→note: The relationship between strong and weak entity is represented by a double diamond (fig
)
➢ One-to-many relationship:-When only one instance of the entity on the left, and
more than one instance of an entity on the right associates with the relationship
then this is known as a one-to-many relationship.
-cardinality is many to one
-Eg; Scientist can invent many inventions, but the invention is done by the only
specific scientist.
➢ Many-to-one relationship:- When more than one instance of the entity on the left,
and only one instance of an entity on the right associates with the relationship then
it is known as a many-to-one relationship.
-For example, a student can take only one course but one course can be taken by
many students
➢ Many-to-many relationship:- When more than one instance of the entity on the left,
and more than one instance of an entity on the right associates with the relationship
then it is known as a many-to-many relationship.
-eg; a student can take more than one course and one course can be taken by many
students
1. Total Participation:-It specifies that each entity in the entity set must
compulsorily participate in at least one relationship instance in that
relationship set.
-It is represented using a double line
between the entity set and relationship
set
-It is also called mandatory participation
2. Partial Participation:- > It specifies that each entity in the entity set may or
may not participate in the relationship instance in that relationship set.
-It is represented using a single line
Between the entity set and
relationship set.
- Fig of total and Partial Participation in a er model
-Eg; If each student must enroll in a course, the participation of student will be total
Participation .
-If some courses are not enrolled by any of the student, the participation of course will be
partial Participation.
➢ weak entity:- A weak entity set is an entity set which do not contain a primary key .
-In other words, a primary key does not exist for a weak entity set.
-Here employee is a strong
entity because it has a primary
key (ssn) and dependents
is a weak entity because of
no primary key.
-so dependents entity have attributes pname and age and we set pname as partial
key.
-use of partial key in a weak entity set and primary key in strong entity are combined
to identify each entity in the weak entity set. <-or->
The combination of partial key and
primary key of the strong entity set makes
it possible to uniquely identify all entities
of the weak entity set.
-partial key called as a discriminator.
-partial key /discriminator is represented by underlining with a dashed line.
➢ Class Hierarchies:- Class hierarchy can be viewed one of two ways
● Specialization (Top Down Approach):-Specialization is a process of identifying
subsets of an entity that shares different characteristics.
-It breaks an entity into multiple entities from higher level (super class) to
lower level (subclass).
-The class vehicle can be specialized into Car, Truck and Motorcycle ( Top
Down Approach)
-Hence, vehicle is the superclass
and Car, Truck, Motorcycle are
subclasses.
-All three of these inherit
attributesfrom Vehicle.
___________________________________________________________________________
*Creating and Modifying Relations Using SQL:-The CREATE TABLE statement is used
to define a new table.
-Data Definition Language (DDL) supports the creation, deletion, and modification of tables.
-To create the Students relation, we can use the following statement:
CREATE TABLE Students ( sid INT, name CHAR(30), login CHAR(20), age INT );
-Tuples are inserted ,using the INSERT command.
-We can insert a single tuple into the Students table as follows:
INSERT INTO Students VALUES (53688,’Smith’,’smith@ee’,18);
-We can delete tuples using the DELETE command.
-We can delete all Students tuples with name equal to Smith using the command:
DELETE FROM Students WHERE name=’Smith’ ;
-We can modify the column values in an existing row using the UPDATE command.
-For example, we can increment the age of the student with sid 53688:
UPDATE Students SET age =age+1 WHERE sid = 53688 ;
-The WHERE clause determines which rows are to be modified.
-The SET clause then determines how these rows are to be modified.
➢ Foreign Key Constraints:-A foreign key is different from a super key, candidate key or
primary key because a foreign key is the one that is used to link two tables together
or create connectivity between the two.
-A foreign key is the one that is used to link two tables together the primary key.
- It means the columns of one table points to the primary key attribute of the other
table.
-The use of a foreign key is simply to link the attributes of two tables together with
the help of a primary key attribute.
- it is used for creating and maintaining the relationship between the two relations.
-example; Consider two tables Student and Department having their respective
attributes as shown in the below table structure:
-In the tables, one attribute, you can see, is common, that is Stud_Id.
-In the Student table, the field Stud_Id is a primary key because it is uniquely
identifying all other fields of the Student table.
-On the other hand, Stud_Id is a foreign key attribute for the Department table
because it is acting as a primary key attribute for the Student table.
-It means that both the Student and Department table are linked with one another
because of the Stud_Id attribute.
-In the below-shown figure, you can view the relationship between the two tables.
➢ Domain constraints:-Domain constraints can be defined as the definition of a valid
set of values for an attribute.
-The data type of domain includes string, character, integer, time, date, currency, etc.
The value of the attribute must be available in the corresponding domain.
-fig
5.Translating Weak Entity Sets:-A weak entity set always participates in a one-to-many
binary relationship and has a key constraint and total participation.
-the weak entity has only a partial key. Also, when an owner entity is deleted, we want all
owned weak entities to be deleted.
-Consider the Dependents weak entity set with partial key pname.
-A Dependents entity can be identified uniquely only if we take the key of the owning
Employees entity and the pname of the Dependents entity, and the Dependents entity
must be deleted if the owning Employees entity is deleted.
___________________________________________________________________________
*Basic Queries in SQL:-A DBMS would typically execute a query in a different and more
efficient way.
-The basic form of an SQL query is as follows:
● SELECT [DISTINCT] select-list
● FROM from-list
● WHERE qualification
-Every query must have a SELECT clause and a FROM clause,The WHERE clause is optional.
*UNION,INTERSECT and EXCEPT:-UNION, EXCEPT, and INTERSECT are operators that
operate similarly and are used between two queries to form Boolean combinations between
the results of the two queries.
-Given queries A and B, UNION returns all records returned by either A or B.
-EXCEPT returns all records in A but not in B.
-INTERSECT returns all records returned by both A and also by B.
-eg:Consider the tables called Invoices and Students.
-The Invoices table lists invoices for construction work done by named people, with some
names appearing more than once.
-The Students table lists names of students.
-Some names appear in both tables.
-We can form Boolean combinations between the results of queries involving those tables.
-For example, we may want to know the names of all people working on construction
projects who are not students.
- The UNION, EXCEPT, and INTERSECT operators can form Boolean combinations between
any two queries.
-Examples: SELECT Name FROM Invoices UNION SELECT Name FROM Students;
-The query above returns a table with all names found either in the Invoices table or in the
Students table, removing duplicates.
- To keep duplicates in the results table, we use ALL:
-eg: SELECT Name FROM Invoices UNION ALL SELECT Name FROM Students;
→Except
-eg:SELECT Name FROM Invoices EXCEPT SELECT Name FROM Students;
-The query above returns a table with all names found in the Invoices table except those
who are students, removing duplicates.
To keep duplicates in the results table, we use ALL:
→INTERSECT
-eg:SELECT Name FROM Invoices INTERSECT SELECT Name FROM Students;
-The query above returns a table with all names found in the Invoices table who also are
students, removing duplicates.
-To keep duplicates in the results table, we use ALL:
-Note:INTERSECT has priority over UNION or EXCEPT.
* Nested Queries:-One of the most powerful features of SQL is nested queries.
-A nested query is a query that has another query embedded within it; the embedded query
is called a subquery.
-The embedded query can of course be a nested query itself.
-A subquery typically appears within the WHERE clause of a query.
-It can sometimes appear in the FROM clause or HAVING clause.
-Example: Find the names of employee who have regno=103
-The query is as follows −
select E.ename from employee E where E.eid IN (select S.eid from salary S where
S.regno=103);
-There are mainly two types of nested queries:
1. Independent Nested Queries:-In independent nested queries, query execution starts
from innermost query to outermost queries.
-The execution of inner query is independent of outer query, but the result of inner
query is used in execution of outer query.
-Various operators like IN, NOT IN, ANY, ALL etc are used in writing independent
nested queries.
-eg:
-If we want to find out S_ID who are enrolled in C_NAME ‘DSA’ or ‘DBMS’, we can
write it with the help of independent nested query and IN operator. From COURSE
table, we can find out C_ID for C_NAME ‘DSA’ or DBMS’ and we can use these C_IDs
for finding S_IDs from STUDENT_COURSE TABLE.
2. Co-related Nested Queries:-: In co-related nested queries, the output of inner query
depends on the row which is being currently executed in outer query.
-e.g.; If we want to find out S_NAME of STUDENTs who are enrolled in C_ID ‘C1’, it
can be done with the help of co-related nested query as:
Select S_NAME from STUDENT S where EXISTS
-For each row of STUDENT S, it will find the rows from STUDENT_COURSE where
S.S_ID = SC.S_ID and SC.C_ID=’C1’. If for a S_ID from STUDENT S, atleast a row exists
in STUDENT_COURSE SC with C_ID=’C1’, then inner query will return true and
corresponding S_ID will be returned as output.
*Aggregate Operators:-aggregation function is used to perform the calculations on
multiple rows of a single column of a table. It returns a single value.
Or
-In database management an aggregate function is a function where the values of multiple
rows are grouped together as input on certain criteria to form a single value of more
significant meaning.
-It is also used to summarize the data.
-Types of SQL Aggregation Function are;
3. Avg():-he AVG function is used to calculate the average value of the numeric type.
-Syntax: AVG()
-Example: SELECT AVG(COST) FROM PRODUCT_MAST;
Output:67.00
*String and Date Functions:-String functions are used to perform an operation on input
string and return an output string.
-String functions are the predefined functions that allow the database users for string
manipulation.
-Following are the most important string functions:
● ASCII():-This function is used to find the ASCII value of a character.
● CHAR_LENGTH():-This string function returns the length of the specified word. It
shows the number of characters from the word.
-Syntax: SELECT char_length('Hello!');
Output: 6
● LCASE():-This function is used to convert the given string into lower case.
Syntax: LCASE ("GeeksFor Geeks To Learn");
Output: geeksforgeeks to learn
● LOWER():-his function is used to convert the upper case string into lower case.
Syntax: SELECT LOWER('GEEKSFORGEEKS.ORG');
Output: geeksforgeeks.org
-The date and time functions in DBMS are quite useful to manipulate and store values
related to date and time.
-Here are some of the important date functions which are in-built in SQL;
● NOW():-It Returns the current date and time.
Syntax: SELECT NOW();
Output:2023-04-30 02:58:30
● Domain Constraints:-A user can define a new domain using CREATE DOMAIN
statement which make use of CHECK constraints.
-CREATE DOMAIN ratingval INTEGER DEFAULT 0
CHECK (VALUE>=1 AND VALUE<=10)
*Embedded SQL:-The use of SQL commands within a host language program is called
Embedded SQL.
-Embedded SQL is the one which combines the high level language with the DB language like
SQL.
-It allows the application languages to communicate with DB and get requested result.
-The high level languages which supports embedding SQLs within it are also known as host
language.
-There are different host languages which support embedding SQL within it like C, C++, ADA,
Pascal, FORTRAN, Java etc.
-When SQL is embedded within C or C++, then it is known as Pro*C/C++ or simply Pro*C
language.
-Pro*C is the most commonly used embedded SQL.
-or google nokkuka
*Dynamic SQL:-SQL statements can be executed in one of two ways: statically or
dynamically.
1. Static SQL:-For statically executed SQL statements, the syntax is fully known at
precompile time.
2. Dynamic SQL:- is a programming technique that could be used to write SQL queries
during runtime.
-Dynamic SQL could be used to create general and flexible SQL queries.
-bakki google.
*Cursors:-Whenever DML statements are executed, a temporary work area is created in
the system memory and it is called a cursor.
-A cursor can have more than one row, but processing wise only 1 row is taken into account.
-Cursors are very helpful in all kinds of databases like Oracle, SQL Server, MySQL, etc.
-Two different types of cursors are available.
1. Implicit cursors:-These types of cursors are generated and allocated by the SQL
server when the system performs INSERT, DELETE, and UPDATE operations on SQL
queries.
-This cursor is also referred to as the default cursor in SQL.
-An implicit cursor is also created by the system when the SELECT query selects the
single row.
2. Explicit cursors:-These types of cursors are created by the user using the SELECT
query.
-An explicit cursor holds multiple records but processes a single row at a time. It uses
the pointer, which moves to another row after reading one row.
-It is basically used for gaining extra control over the temporary workstation.
___________________________________________________________________________
Module-4-Transaction Management
->Atomicity:-By this, we mean that either the entire transaction takes place at once or
doesn’t happen at all.
-There is no midway i.e. transactions do not occur partially.
-ach transaction is considered as one unit and either runs to completion or is not executed
at all.
-Atomicity involves the following two operations:
1. Abort: If a transaction aborts then all the changes made are not visible.
2. Commit: If a transaction commits then all the changes made are visible.
-Atomicity is also known as the ‘All or nothing rule’.
-Example:Consider the following transaction T consisting of T1 and T2: Transfer of 100 from
account X to account Y.
-If the transaction fails after completion of T1 but before completion of T2.( say, after
write(X) but before write(Y)), then the amount has been deducted from X but not added to
Y.
-This results in an inconsistent database state.
-Therefore, the transaction must be executed in its entirety in order to ensure the
correctness of the database state.
->Isolation:-It shows that the data which is used at the time of execution of a transaction
cannot be used by the second transaction until the first one is completed.
-In isolation, if the transaction T1 is being executed and using the data item X, then that data
item can't be accessed by any other transaction T2 until the transaction T1 ends.
-Example: Let X= 500, Y = 500. Consider two transactions T and T”.
-Suppose T has been executed till Read (Y) and
then T’’ starts. As a result, interleaving of
operations takes place due to which T’’ reads the
correct value of X but the incorrect value of Y
and sum computed by
T’’: (X+Y = 50, 000+500=50, 500)
is thus not consistent with the sum at end of the transaction:
T: (X+Y = 50, 000 + 450 = 50, 450).
-This results in database inconsistency, due to a loss of 50 units. Hence, transactions must
take place in isolation and changes should be visible only after they have been made to the
main memory.
->Durability:-This property ensures that once the transaction has completed execution, the
updates and modifications to the database are stored in and written to disk and they persist
even if a system failure occurs.
-These updates now become permanent and are stored in non-volatile memory.
-The effects of the transaction, thus, are never lost.
2. Dirty read problem (W-R conflict):-This type of problem occurs when one
transaction T1 updates a data item of the database, and then that transaction fails
due to some reason, but its updates are accessed by some other transaction.
-Example: Let's take the value of A is 100
-fig explanation
❖ At t1 time, T1 transaction reads the value of A i.e., 100.
❖ At t2 time, T1 transaction adds the value of A by 20.
❖ At t3 time, T1transaction writes the value of A (120) in the
database.
❖ At t4 time, T2 transactions read the value of A data item
i.e., 120.
❖ At t5 time, T2 transaction adds the value of A data item by
30.
❖ At t6 time, T2transaction writes the value of A (150) in the database.
❖ At t7 time, a T1 transaction fails due to power failure then it is rollback according to
atomicity property of transaction (either all or none).
❖ So, transaction T2 at t4 time contains a value which has not been committed in the
database. The value read by the transaction T2 is known as a dirty read.
2. Exclusive lock:-In the exclusive lock, the data item can be both reads as well as
written by the transaction.
-This lock is exclusive, and in this lock, multiple transactions do not modify the same
data simultaneously.
-Consider a transaction(T2) which requires to update the data item value A. The
following steps take place when lock protocol is applied to this traction
● T2 will acquire an exclusive lock on the data item A.
● Read the current value of data item A.
● Modify the data item as required. In the example illustrated, a value of 50 is
subtracted from the data item A.
● Write the updated value of the data item.
● Once the transaction is completed, the data item will be unlocked.
*Crash Recovery:-Crash recovery is the process by which the database is moved back to a
consistent and usable state.
-This is done by rolling back incomplete transactions and completing committed transactions
that were still in memory when the crash occurred.
-Conditions that can result in transaction failure
● A power failure on the machine causing the database manager and the database
partitions on it to go down.
● A hardware failure such as memory corruption, or disk, CPU, or network failure.
● A serious operating system error that causes the DB to go down
-Then a DBMs is restarted after crashes. the recovery manager is given control
and must bring the database to a consistent state.
-The recovery manager is also responsible for undoing the actions of an aborted transaction.
*Dealing with Deadlocks:-A deadlock is a condition where 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 no task ever gets
finished and is in waiting state forever.
-For example: In the student table, transaction T1 holds a lock on some rows and needs to
update some rows in the grade table. Simultaneously, transaction T2 holds locks on some
rows in the grade table and needs to update the rows in the Student table held by
Transaction T1.
-Now, the main problem arises. Now Transaction T1 is waiting for T2 to release its lock and
similarly, transaction T2 is waiting for T1 to release its lock.
->Deadlock Detection:In a database, when a transaction waits indefinitely to obtain a lock,
then the DBMS should detect whether the transaction is involved in a deadlock or not.
-The lock manager maintains a Wait for the graph to detect the deadlock cycle in the
database.
❖ Wait for Graph:-This is the suitable method for deadlock detection. In this method, a
graph is created based on the transaction and their lock.
-If the created graph has a cycle or closed loop, then there is a deadlock.
No deadlock->
->Deadlock prevention: For a large database, the deadlock prevention method is
suitable.
- A deadlock can be prevented if the resources are allocated in such a way that a
deadlock never occurs.
-Deadlock prevention mechanism proposes two schemes:
1. Wait-Die Scheme:-In this scheme, If a transaction requests a resource that is
locked by another transaction, then the DBMS simply checks the timestamp
of both transactions and allows the older transaction to wait until the
resource is available for execution.
-Suppose, there are two transactions T1 and T2, and Let the timestamp of any
transaction T be TS (T). Now, If there is a lock on T2 by some other transaction
and T1 is requesting resources held by T2, then DBMS performs the following
actions:
-Checks if TS (T1) < TS (T2) – if T1 is the older transaction and T2 has held
some resource, then it allows T1 to wait until resource is available for
execution.
-That means if a younger transaction has locked some resource and an older
transaction is waiting for it, then an older transaction is allowed to wait for it
till it is available.
-If T1 is an older transaction and has held some resource with it and if T2 is
waiting for it, then T2 is killed and restarted later with random delay but with
the same timestamp. i.e.
if the older transaction has held some resource and the younger transaction
waits for the resource, then the younger transaction is killed and restarted
with a very minute delay with the same timestamp.
-This scheme allows the older transaction to wait but kills the younger one.
Or
-Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held some
resource, then Ti is allowed to wait until the data-item is available for
execution. That means if the older transaction is waiting for a resource which
is locked by the younger transaction, then the older transaction is allowed to
wait for resource until it is available.
-Check if TS(Ti) < TS(Tj) - If Ti is older transaction and has held some resource
and if Tj is waiting for it, then Tj is killed and restarted later with the random
delay but with the same timestamp.
→differences between Wait – Die and Wound -Wait scheme prevention schemes are;
*Distributed Data Storage :There are 2 ways in which data can be stored on different
sites. These are:
1. Replication:-In this approach, the entire relationship is stored redundantly at 2 or
more sites. If the entire database is available at all sites, it is a fully redundant
database.
-Hence, in replication, systems maintain copies of data.
-This is advantageous as it increases the availability of data at different sites. Also,
now query requests can be processed in parallel.
-However, it has certain disadvantages as well.
-Data needs to be constantly updated. Any change made at one site needs to be
recorded at every site that relation is stored or else it may lead to inconsistency. This
is a lot of overhead.
-Also, concurrency control becomes way more complex as concurrent access now
needs to be checked over a number of sites.
2. Fragmentation:-In this approach, the relations are fragmented (i.e., they’re divided
into smaller parts) and each of the fragments is stored in different sites where
they’re required.
- It must be made sure that the fragments are such that they can be used to
reconstruct the original relation (i.e, there isn’t any loss of data).
-Fragmentation is advantageous as it doesn’t create copies of data, consistency is not
a problem.
-Fragmentation of relations can be done in two ways:
● Horizontal fragmentation – Splitting by rows – The relation is fragmented into
groups of tuples so that each tuple is assigned to at least one fragment.
● Vertical fragmentation – Splitting by columns – The schema of the relation is
divided into smaller schemas. Each fragment must contain a common
candidate key so as to ensure a lossless join.
-In certain cases, an approach that is hybrid of fragmentation and replication is used.
___________________________________________________________________________
Note;
Mod1:- data users,
Mod2:-Types of Integrity Constraint (1.Domain constraints, 2.Entity integrity constraints,
3.Referential Integrity Constraints,4.Key constraints)
Mod 3:-Schedules Involving Aborted Transactions.