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

DBMS Que

Data independence refers to the ability to modify a database's structure or schema without requiring changes to application programs. There are two types of data independence: physical data independence, which concerns how data is physically stored, and logical data independence, which concerns changes to the logical structure or definition of data. Achieving different levels of data independence helps ensure that changes to the database over time do not require extensive modifications to application code or programs.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
77 views

DBMS Que

Data independence refers to the ability to modify a database's structure or schema without requiring changes to application programs. There are two types of data independence: physical data independence, which concerns how data is physically stored, and logical data independence, which concerns changes to the logical structure or definition of data. Achieving different levels of data independence helps ensure that changes to the database over time do not require extensive modifications to application code or programs.

Uploaded by

Vishal
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

1

QUE. WHAT IS DATA INDEPENDENCE ? Difference between Physical and Logical Data Independence

Data independence is the ability to modify the scheme without affecting the programs and the application
to be rewritten. Data is separated from the programs, so that the changes made to the data will not affect
the program execution and the application.
We know the main purpose of the three levels of data abstraction is to achieve data independence. If the
database changes and expands over time, it is very important that the changes in one level should not
affect the data at other levels of the database. This would save time and cost required when changing the
database.
Difference Between Physical and Logical Data Independence

Physical Data Independence Logical Data Independence

It primarily concerns the manner in which data is The structure of the evolving data definition was the
saved within the system. key topic.

It is simple to get back. Data retrieval is challenging since it mostly depends on


the logical organization of the data.

The main focus of logical data independence is on Logical data independence is mostly interested in data
altering the definition or structure of the data. storage.

In most cases, a change at the physical level does not If new fields are added to or removed from the
necessitate a change at the application program level. database, changes must be made in the application
software.

It is mostly focused on data storage. It is mostly interested in modifying the data definition
or structure.

It may or may not be necessary to make adjustments Anytime the logical structures of the database are
at the internal levels to enhance the structure's modified, there must be significant modifications at the
performance. logical levels.

QUE 2 EXPLAIN DATABASE LANGUAGE WITH THE HELP OF EXAMPLE :


Database Languages are the set of statements, that are used to define and manipulate a database.
A Database language has Data Definition Language (DDL), which is used to construct a database & it has Data
Manipulation Language (DML), which is used to access a database. DDL implements database schema at
the physical, logical and external level. While, the DML provides the statements
to retrieve, modify, insert and delete the data from the database. In this section, we will discuss the database
language in detail. Data Definition Language :
The language is used to create database, tables, alter them, etc. With this, you can also rename the database, or
drop them. It specifies the database schema.
The DDL statements include −
• CREATE: Create new database, table, etc.
• ALTER: Alter existing database, table, etc.
• DROP: Drop the database
• RENAME: Set a new name for the table.
Data Manipulation Language
The language used to manipulate the database like inserting data, updating table, retrieving record from a table,
etc. is known as Data Manipulation Language −
• SELECT: Retrieve data from the database
2

• INSERT: Insert data


• UPDATE: Update data
• DELETE: Delete all records
Data Control Language
Grant privilege to a user using the GRANT statement. In the same way, revoke the privilege using the REVOKE
statement. Both of these statements come under the Data Control Language (DCL). −
• GRANT: Give privilege to access the database.
• REVOKE: Take back the privilege to access the database.
Transaction Control Language
Manage transactions in the Database using the Transaction Control Language −
• COMMIT: Save the work.
• SAVEPOINT: Set a point in transaction to rollback later
• ROLLBACK: Restores since last commit
QUE3 WHAT IS DATABASE SYSTEME
A database is a systematic collection of data. They support electronic storage and manipulation of data.
Databases make data management easy.
Let us discuss a database example: An online telephone directory uses a database to store data of people, phone
numbers, and other contact details. Your electricity service provider uses a database to manage billing, client-
related issues, handle fault data, etc.
Let us also consider Facebook. It needs to store, manipulate, and present data related to members, their friends,
member activities, messages, advertisements, and a lot more. We can provide a countless number of examples
for the usage of databases.
NEED OF DBMS :
It provides us with the many functionalities and is more advantageous than the traditional file system in many
ways listed below:
1) Processing Queries and Object Management:
In traditional file systems, we cannot store data in the form of objects. In practical-world applications, data is
stored in objects and not files. So in a file system, some application software maps the data stored in files to
objects so that can be used further.
2) Controlling redundancy and inconsistency:
Redundancy refers to repeated instances of the same data. A database system provides redundancy control
whereas in a file system, same data may be stored multiple times. For example, if a student is studying two
different educational programs in the same college, say ,Engineering and History, then his information such as
the phone number and address may be stored multiple times, once in Engineering dept and the other in History
dept
3) Efficient memory management and indexing:
DBMS makes complex memory management easy to handle. In file systems, files are indexed in place of objects
so query operations require entire file scans whereas in a DBMS , object indexing takes place efficiently through
database schema based on any attribute of the data or a data-property. This helps in fast retrieval of data based
on the indexed attribute.
4) Concurrency control and transaction management:
Several applications allow user to simultaneously access data. This may lead to inconsistency in data in case files
are used. Consider two withdrawal transactions X and Y in which an amount of 100 and 200 is withdrawn from an
account A initially containing 1000. A DBMS implements ACID(atomicity, durability, isolation,consistency)
properties to ensure efficient transaction management without data corruption.
5) Access Control and ease in accessing data:
A DBMS can grant access to various users and determine which part and how much of the data can they access
from the database thus removing redundancy. Otherwise in file system, separate files have to be created for each
user containing the amount of data that they can access
3

6) Integrity constraints: Data stored in databases must satisfy integrity constraints. For example, Consider a
database schema consisting of the various educational programs offered by a university such
as(B.Tech/M.Tech/B.Sc/M.Sc/BCA/MCA) etc. Then we have a schema of students enrolled in these programs. A
DBMS ensures that it is only out of one of the programs offered schema , that the student is enrolled in, i.e. Not
anything out of the blue. Hence, database integrity is preserved.

Apart from the above mentioned features a database management also provides the following:
• Multiple User Interface
• Data scalability, expandability and flexibility: We can change schema of the database, all schema
will be updated according to it.
• Overall the time for developing an application is reduced.
• Security: Simplifies data storage as it is possible to assign security permissions allowing restricted
access to data.
QUE4. WHAT IS DATA MODEL ? DIFFERENTTYPES OF DATA MODELS :
Data models define how the logical structure of a database is modeled. Data Models are fundamental entities to
introduce abstraction in a DBMS. Data models define how data is connected to each other and how they are
processed and stored inside the system.
The very first data model could be flat data-models, where all the data used are to be kept in the same plane.
Earlier data models were not so scientific, hence they were prone to introduce lots of duplication and update
anomalies.
1) Relational Data Model: This type of model designs the data in the form of rows and columns within a
table. Thus, a relational model uses tables for representing data and in-between relationships. Tables are also
called relations. This model was initially described by Edgar F. Codd, in 1969. The relational data model is the
widely used model which is primarily used by commercial data processing applications.
2) Entity-Relationship Data Model: An ER model is the logical representation of data as objects and relationships
among them. These objects are known as entities, and relationship is an association among these entities. This
model was designed by Peter Chen and published in 1976 papers. It was widely used in database designing. A set
of attributes describe the entities. For example, student_name, student_id describes the 'student' entity. A set of
the same type of entities is known as an 'Entity set', and the set of the same type of relationships is known as
'relationship set'.
3) Object-based Data Model: An extension of the ER model with notions of functions, encapsulation, and object
identity, as well. This model supports a rich type system that includes structured and collection types. Thus, in
1980s, various database systems following the object-oriented approach were developed. Here, the objects are
nothing but the data carrying its properties.
4) Semistructured Data Model: This type of data model is different from the other three data models (explained
above). The semistructured data model allows the data specifications at places where the individual data items
of the same type may have different attributes sets. The Extensible Markup Language, also known as XML, is
widely used for representing the semistructured data. Although XML was initially designed for including the
markup information to the text document, it gains importance because of its application in the exchange of data.
QUE5. WHAT IS VIEW?
Writing Complex queries and Securing Database access is very challenging for any Database Developer and
Database Administrator. Sometimes SQL queries get very complicated by joins, Group By clauses, and other
referential dependencies, So those Types of queries can be simplified to proxy data or virtual data which
simplifies the queries.
Views act as a proxy or virtual table created from the original table. Views simplify SQL queries and allow
secure access to underlying tables. Views in DBMS can be visualized as virtual tables that are formed by original
tables from the database.
HOW VIEW CAN BE CREATED : The following statement defines the syntax of a view:
4

Syntax of the Create View Statement (MySQL)


CREATE
[OR REPLACE]
[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]
VIEW view_name [(column_list)]
AS select_statement
[WITH [CASCADED | LOCAL] CHECK OPTION]
This guide will cover this part of of the statement…
CREATE
VIEW view_name [(column_list)]
AS select_statement
Sample View creation from the student tables
Notes:
• The name of the view has a “v” at the end. It’s recommended that the view name indicate that it’s a view
in some way to make life easier for programmers and database administrators. Your IT shop should have
its own rules on naming objects.
• The columns in the view are limited by the SELECT and the rows of data by the WHERE clause.
• the ”`” character around the view names is required because of the ”-” in the names. MySQL reports an
error without them.
create view `programming-students-v` as
select FullName, programOfStudy
from student
where programOfStudy = 'Programming';

select * from `programming-students-v`;


QUE.6 EXPLAIN OUTER JOIN OPERATION AND MODIFICATION OF DATABASE
OUTER JOIN : An outer join in SQL is a specific kind of query construction that deliberately allows for a wider
array of results. The process of building specific queries in SQL to get database results is a highly technical one,
and an outer join is an example of a type of detail learned and utilized by database researchers.
Someone who is writing a query can use a left or right outer join to include table results that only have a
given component, rather than requiring multiple components to be present. A left outer join includes all rows in
a table regardless of whether a specifically positioned column has results or not. By contrast, an inner join
requires both components to be present.
Because outer joins provide for more diversity, they are often useful in searches that are less rigid and do not
require strict adherence to the principle of having consistent data from multiple search components.
explain modification of database :
KEYS in DBMS is an attribute or set of attributes which helps you to identify a row(tuple) in a relation(table). They
allow you to find the relation between two tables. Keys help you uniquely identify a row in a table by a
combination of one or more columns in that table. Key is also helpful for finding unique record or row from the
table. Database key is also helpful for finding unique record or row from the table.
1)SUPER KEY : A superkey is a combination of columns that uniquely identifies any row within a relational
database management system (RDBMS) table. A candidate key is a closely related concept where the superkey is
reduced to the minimum number of columns required to uniquely identify each row.
As an example, a table used to store customer master details could contain columns such as:
• Customer name
• Customer ID
5

• Social Security number (SSN)


• Address
• Date of birth
A certain set of columns may be extracted and guaranteed unique to each customer. Examples of superkeys are
as follows:
• Name+SSN+Birthdate
• ID+Name+SSN
However, this process may be further reduced. It can be assumed that the customer ID is unique to each
customer. Therefore, the superkey may be reduced to just one field, customer ID, which is the candidate key.
However, to ensure absolute uniqueness, a composite candidate key may be formed by combining customer ID
with SSN.
PRIMARY KEY in DBMS is a column or group of columns in a table that uniquely identify every row in that table.
The Primary Key can’t be a duplicate meaning the same value can’t appear more than once in the table. A table
cannot have more than one primary key.
Example:
In the following example, <code>StudID</code> is a Primary Key.
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]

CANDIDATE KEY in SQL is a set of attributes that uniquely identify tuples in a table. Candidate Key is a super key
with no repeated attributes. The Primary key should be selected from the candidate keys. Every table must have
at least a single candidate key. A table can have multiple candidate keys but only a single primary key.
Candidate key Example: In the given table Stud ID, Roll No, and email are candidate keys which help us to
uniquely identify the student record in the table.
StudID Roll No First Name LastName Email
1 11 Tom Price [email protected]
2 12 Nick Wright [email protected]
3 13 Dana Natan [email protected]
A foreign key is a column or group of columns in a relational database table that provides a link between data in
two tables. It acts as a cross-reference between tables because it references the primary key of another table,
thereby establishing a link between them.
The majority of tables in a relational database system adhere to the foreign key concept. In complex databases
and data warehouses, data in a domain must be added across multiple tables, thus maintaining a relationship
between them. The concept of referential integrity is derived from foreign key theory.
QUE.7 DEFINE EXTERNAL SORT. EXTERNAL SORT MERGE ALGORITHM :
An external sorting algorithm is an algorithm that can handle massive amounts of information. Users utilize it
when the data that needs sorting doesn’t fit into a computer’s primary memory (usually the random access
memory [RAM]). In such a case, you must place the information in an external memory device (usually a hard
disk drive [HDD]). External sorting algorithms typically use a hybrid sort-merge strategy, which allows a computer
to sort data into chunks small enough to fit in the RAM. Each chunk is read, sorted, and written out to a
temporary file. Once the entire mass gets sorted, the outputs get merged to form a single larger file.
External merge sort
6

The external merge sort is a technique in which the data is stored in intermediate files and then each
intermediate files are sorted independently and then combined or merged to get a sorted data.
For example: Let us consider there are 10,000 records which have to be sorted. For this, we need to apply the
external merge sort method. Suppose the main memory has a capacity to store 500 records in a block, with
having each block size of 100 records.

In this example, we can see 5 blocks


will be sorted in intermediate files.
This process will be repeated 20
times to get all the records. Then by
this, we start merging a pair of
intermediate files in the main
memory to get a sorted output.

Algorithm for Two-Way Merge Sort:


Step 1) Divide the elements into the blocks of size M. Sort each block and then write on disk.
Step 2) Merge two runs
1. Read first value on every two runs.
2. Then compare it and sort it.
3. Write the sorted record on the output tape.
Step 3) Repeat the step 2 and get longer and longer runs on alternates tapes. Finally, at last, we will get a single
sorted list.
7

QUE.8 explain heuristic optimization with example :


Cost-based optimization is expensive. Heuristics are used to reduce the number of choices that must be made in
a cost-based approach.
Rules
Heuristic optimization transforms the expression-tree by using a set of rules which improve the performance.
These rules are as follows −
• Perform the SELECTION process foremost in the query. This should be the first action for any SQL table. By
doing so, we can decrease the number of records required in the query, rather than using all the tables
during the query.
• Perform all the projection as soon as achievable in the query. Somewhat like a selection but this method
helps in decreasing the number of columns in the query.
• Perform the most restrictive joins and selection operations. What this means is that select only those sets
of tables and/or views which will result in a relatively lesser number of records and are extremely
necessary in the query. Obviously any query will execute better when tables with few records are joined.
Some systems use only heuristics and the others combine heuristics with partial cost-based optimization.
Steps in heuristic optimization
Let’s see the steps involve in heuristic optimization, which are explained below −
• Deconstruct the conjunctive selections into a sequence of single selection
operations.
• Move the selection operations down the query tree for the earliest possible
execution.
• First execute those selections and join operations which will produce
smallest relations.
• Replace the cartesian product operation followed by selection
operation with join operation.
• Deconstructive and move the tree down as far as possible.
• Identify those subtrees whose operations are pipelined.
Example of Heuristic Query Optimization
1. Original Query Tree
QUE.9 explain shadow copy technique for atomicity and durability :
• In the shadow-copy scheme, a transaction
that wants to update the database first
creates a complete copy of the database. All
updates are done on the new database
copy, leaving the original copy, the shadow
copy, untouched. If at any point the
transaction has to be aborted, the system
merely deletes the new copy. The old copy
of the database has not been affected.
• This scheme is based on making copies of
the database, called shadow copies,
assumes that only one transaction is active
at a time. The scheme also assumes that the
database is simply a file on disk. A pointer
called db-pointer is maintained on disk; it
points to the current copy of the database.
If the transaction completes, it is committed as follows:
8

• First, the operating system is asked to make sure that all pages of the new copy of the database have been
written out to disk. (Unix systems use the flush command for this purpose.)
• After the operating system has written all the pages to disk, the database system updates the pointer db-
pointer to point to the new copy of the database; the new copy then becomes the current copy of the
database. The old copy of the database is then deleted.
Figure below depicts the scheme, showing the database state before and after the update.
The transaction is said to have been committed at the point where the updated db pointer is written to disk
Que. 10 explain view serializability AND Blind write :
DBMS View Serializability is a method to discover that a specified schedule is either view serializable or not. To
prove whether a specified schedule is view serializable, the user involves testing whether the agreed schedule is
View Equivalent to its serial schedule. Since there is no synchronized transactions execution, we can confirm that
a serial schedule will certainly not leave the database unpredictable. Conversely, the database can be left in an
inconsistent state in a non-serial schedule because there exist multiple transactions executing concurrently in the
database server. By testing that a specified non-serial schedule is view serializable, we need to ensure that it
holds a consistent schedule.

Blind write : In computing, a blind write occurs when a transaction writes a value without reading it.
Any view serializable schedule that is not conflict serializable must contain a blind write. blind write
is simply when a transaction writes without reading. i.e a transaction have WRITE(Q), but no
READ(Q) before it. So, the transaction is writing to the database "blindly" without reading previous
value.
Blind write : Performing the Writing operation (updation), without reading operation, such write operation is
known as a blind write. If no blind write exists, then the schedule must be a non-View-Serializable schedule. Stop
and submit your final answer.
Que.Explain ACID properties of transaction :
ACID is an acronym that stands for atomicity, consistency, isolation, and durability.
Together, these ACID properties ensure that a set of database operations (grouped together in a transaction)
leave the database in a valid state even in the event of unexpected errors.
Atomicity :
Atomicity guarantees that all of the commands that make up a transaction are treated as a single unit and either
succeed or fail together. This is important as in the case of an unwanted event, like a crash or power outage, we
can be sure of the state of the database. The transaction would have either completed successfully or been
rollbacked if any part of the transaction failed.
If we continue with the above example, money is deducted from the source and if any anomaly occurs, the
changes are discarded and the transaction fails.
Consistency :
Consistency guarantees that changes made within a transaction are consistent with database constraints. This
includes all rules, constraints, and triggers. If the data gets into an illegal state, the whole transaction fails.
Going back to the money transfer example, let’s say there is a constraint that the balance should be a positive
integer. If we try to overdraw money, then the balance won’t meet the constraint. Because of that, the
consistency of the ACID transaction will be violated and the transaction will fail.
Isolation :
Isolation ensures that all transactions run in an isolated environment. That enables running transactions
concurrently because transactions don’t interfere with each other.
9

For example, let’s say that our account balance is $200. Two transactions for a $100 withdrawal start at the same
time. The transactions run in isolation which guarantees that when they both complete, we’ll have a balance of
$0 instead of $100.
Durability :
Durability guarantees that once the transaction completes and changes are written to the database, they are
persisted. This ensures that data within the system will persist even in the case of system failures like crashes or
power outages.
The ACID characteristics of transactions are what allow developers to perform complex, coordinated updates and
sleep well at night knowing that their data is consistent and safely stored.
• Example : Atomicity: Money needs to both be removed from one account and added to the other, or the
transaction will be aborted. Removing money from one account without adding it to another would leave
the data in an inconsistent state.
• Consistency: Consider a database constraint that an account balance cannot drop below zero dollars. All
updates to an account balance inside of a transaction must leave the account with a valid, non-negative
balance, or the transaction should be aborted.
• Isolation: Consider two concurrent requests to transfer money from the same bank account. The final
result of running the transfer requests concurrently should be the same as running the transfer requests
sequentially.
• Durability: Consider a power failure immediately after a database has confirmed that money has been
transferred from one bank account to another. The database should still hold the updated information
even though there was an unexpected failure.
Que.11 Explain deadlock
A Deadlock in DBMS can be termed as the undesirable condition which appears when a process waits for a
resource indefinitely whereas this resource is detained by another process. In order to understand the deadlock
concept better, let us consider a transaction T1 which has a
lock on a few rows in the table Employee and it requires to
update some rows in another table Salary. Also, there exists
another transaction T2 that has a lock on the table Salary
and it also requires updating a few rows in the Employee
table which already is held by the transaction T1. In this
situation both the transactions wait for each other to
release the lock and the processes end up waiting for each
other to release the resources. As a result of the above
scenario, none of the tasks gets completed and this is
known as deadlock.
Deadlock Detection :
1. If resources have a single instance –
In this case for Deadlock detection, we can run an algorithm to check for the cycle in the Resource Allocation
Graph. The presence of a cycle in the graph is a sufficient condition for deadlock.
In the above diagram, resource 1 and resource 2 have single instances. There is a cycle R1 → P1 → R2 →
P2. So, Deadlock is Confirmed. 2. If there are multiple instances of resources –
Detection of the cycle is necessary but not sufficient condition for deadlock detection, in this case, the system
may or may not be in deadlock varies according to different situations.
Deadlock Recovery :
A traditional operating system such as Windows doesn’t deal with deadlock recovery as it is a time and space-
consuming process. Real-time operating systems use Deadlock recovery.
10

1. Killing the process –


Killing all the processes involved in the deadlock. Killing process one by one. After killing each process
check for deadlock again keep repeating the process till the system recovers from deadlock. Killing all the
processes one by one helps a system to break circular wait condition.
2. Resource Preemption –
Resources are preempted from the processes involved in the deadlock, preempted resources are allocated
to other processes so that there is a possibility of recovering the system from deadlock. In this case, the
system goes into starvation.
database architecture: A Database store a lot of critical information to access data quickly and securely. Hence it
is important to select a correct Architecture for efficient data management.
1- Tier Architecture:
In One-Tier Architecture the database is directly available to the user, the user can directly sit on the DBMS and
use it i.e.; the client, server, and the Database are all present on the same machine. For Example- To learn SQL we
set up an SQL server and the database on the local system. This enables us to directly interact with the relational
database and execute operations. The industry won’t use this architecture they logically go for 2-Tier and 3-Tier
Architecture.
Two-tier architecture:
The two-tier architecture is similar to a basic client-server model. The application at the client end directly
communicates with the database at the server side. APIs like ODBC and JDBC are used for this interaction. The
server side is responsible for providing query processing and transaction management functionalities. On the
client side, the user interfaces and application programs are run. The application on the client side establishes a
connection with the server side in order to communicate with the DBMS.
An advantage of this type is that maintenance and understanding are easier, and compatible with existing
systems. However, this model gives poor performance when there are a large number of users.
Three Tier architecture:
In this type, there is another layer between the client and the server. The client does not directly communicate
with the server. Instead, it interacts with an application server which further communicates with the database
system and then the query processing and transaction management takes place. This intermediate layer acts as a
medium for the exchange of partially processed data between server and client. This type of architecture is used
in the case of large web applications.
Que13. Explain validation-based protocol:
• Execution of transaction Ti is done in three phases:
i. Read and execution phase: During this phase, the system executes transaction Ti. . It reads the values of the
various data items and stores them in variable local to Ti. It performs all the write operations on temporary local
variables without update of the actual database.
ii. Validation phase: Transaction Ti performs a ``validation test'' to determine if local variables can be written
without violating serializability.
iii. Write phase: If Ti is validated, the updates are applied to the database; otherwise, Ti is rolled back.
• The three phases of concurrently executing transactions can be interleaved, but each transaction must go
through the three phases in that order.
• Also called as optimistic concurrency control since transaction executes fully in the hope that all will go
well during validation.
• Each transaction Ti has 3 timestamps:
i. Start(Ti ) : the time when Ti started its execution
ii. Validation(Ti ): the time when Ti entered its validation phase
iii. Finish(Ti ) : the time when Ti finished its write phase.
• Serializability order is determined by timestamp given at validation time, to increase concurrency. Thus
TS(Ti ) is given the value of Validation(Ti ).
11

• This protocol is useful and gives greater degree of concurrency if probability of conflicts is low. That is
because the serializability order is not pre-decided and relatively less transactions will have to be rolled
back.
• Validation Test for Transaction Tj
i. If for all Ti with TS (Ti ) < TS (Tj ) either one of the following condition
holds:
o finish(Ti ) < start(Tj )
o start(Tj ) < finish(Ti ) < validation(Tj ) and the set of data items
written by Ti does not intersect with the set of data items
read by Tj.
o Then validation succeeds and Tj can be committed.
Otherwise, validation fails and Tj is aborted.
ii. Justification: Either first condition is satisfied, and there is no overlapped
execution, or second condition is satisfied and
o The writes of Tj do not affect reads of Ti since they occur after
Ti has finished its reads.
o the writes of Ti do not affect reads of Tj since Tj does not read any item written by Ti
iii. Schedule Produced by Validation Example of schedule produced using validation
Lock-based Protocols
Database systems equipped with lock-based protocols use a mechanism by which any transaction cannot read or
write data until it acquires an appropriate lock on it.
Locks are of two kinds:
• Binary Locks − A lock on a data item can be in two states; it is either locked or unlocked.
• Shared/exclusive − This type of locking mechanism differentiates the locks based on their uses. If a lock is
acquired on a data item to perform a write operation, it is an exclusive lock. Allowing more than one
transaction to write on the same data item would lead the database into an inconsistent state. Read locks
are shared because no data value is being changed.
There are four types of lock protocols available:
i. Simplistic Lock Protocol
Simplistic lock-based protocols allow transactions to obtain a lock on every object before a 'write' operation is
performed. Transactions may unlock the data item after completing the ‘write’ operation.
ii. Pre-claiming Lock Protocol
Pre-claiming protocols evaluate their operations and create a list of
data items on which they need locks. Before initiating an execution,
the transaction requests the system for all the locks it needs
beforehand. If all the locks are granted, the transaction executes
and releases all the locks when all its operations are over. If all the
locks are not granted, the transaction rolls back and waits until all the locks are granted.
iii. Two-Phase Locking 2PL
12

• This locking protocol divides the execution phase of a


transaction into three parts. In the first part, when
the transaction starts executing, it seeks permission
for the locks it requires.
• The second part is where the transaction acquires all
the locks. As soon as the transaction releases its first
lock, the third phase starts. In this phase, the
transaction cannot demand any new locks; it only releases the acquired locks.
• Two-phase locking has two phases, one is growing, where all the locks are being acquired by the
transaction; and the second phase is shrinking, where the locks held by the transaction are being released.
• To claim an exclusive (write) lock, a transaction must first acquire a shared (read) lock and then upgrade it
to an exclusive lock.
iv. Strict Two-Phase Locking
The first phase of Strict-2PL is same as 2PL. After acquiring all the locks in the first phase, the transaction
continues to execute normally. But in contrast to 2PL, Strict-2PL does not release a lock after using it. Strict-2PL
holds all the locks until the commit point and releases all the locks at a time. Strict-2PL does not have cascading
abort as 2PL does.
Multiple Granularity:
o It can be defined as hierarchically breaking up the
database into blocks which can be locked.
o The Multiple Granularity protocol enhances concurrency
and reduces lock overhead.
o It maintains the track of what to lock and how to lock.
o It makes easy to decide either to lock a data item or to
unlock a data item. This type of hierarchy can be
graphically represented as a tree.
For example: Consider a tree which has four levels of nodes.
o The first level or higher level shows the entire database.
o The second level represents a node of type area. The
higher level database consists of exactly these areas.
o The area consists of children nodes which are known as
files. No file can be present in more than one area.
o Finally, each file contains child nodes known as records.
The file has exactly those records that are its child nodes. No records represent in more than one file.
o Hence, the levels of the tree starting from the top level are as follows: 1.Database 2.Area 3.File
4.Record

Que.15 explain Timestamp- Based Protocols :


The basic idea is to order the transaction based on their timestamps. This protocol ensures that any conflicting
read and write operation are executed in time stamp order. This protocol works as follow:
Suppose that transaction Ti issues read (q)
If Ts(Ti) < W – time stamp (Q)
Then Ti needs to read a value of Q was already overwritten, hence the read operation is rejected and Ti rolled
back. Here co-timestamp (Q) denotes the largest timestamp of any transaction that executed write (Q)
successfully.
13

If Ts (Ti) > w – timestamp (2)


Then Ti needs to read the value of Q i.e. read operation is executed and (Q) is set to the maximum of R and Ts (Ti)
suppose that transaction Ti issues write Q of Ts(Ti) < R – timestamp (q) then the value of Q that Ti is producing
was needed previously, and the spectrum assumed that the value will never be produced.
Hence, the system rejects the write operation and rolls Ti back. If Ts(Ti) < W – write stamp (Q) then Ti is
attempting to write an absolute value of Q, hence, the system rejects this write operation and rolls Ti back.
Otherwise, the system executed the write operation and sits, w- timestamp (Q) to Ts (Ti)
Example:
Suppose there are 2 transactions T1 & T2, T2 displays the content 01 account A and B there as T2 transfer Rs 100
from account A to account B and display sum of both the two transactions T1 & T2 can be illustrated as follow:
Ti : read (A)
Read (B)
Display (A + B)
T2 : read (B)
B = B – 100
Write (B)
Read (A)
A = A + 100
Write (A)
Display (A + B)
Here, the assumption is that a transaction is assigned
to a time stamp immediately before its first instruction. Thus a schedule Ts(t1) < TS(+2)
14

Que.16 Multiversion Schemes in DBMS


Multi-version protocol minimizes the delay for reading operation and maintains different versions of data items.
For each writes operation performed, it creates a new version of transaction data so that whenever any
transaction performs read operation to read that data then the appropriate created data version is selected by
the control manager to make that read operation conflict-free and successful.
When the write operation and new version of data is created then that new version contains some information
that is given below
1. Content: This field contains the data value of that version.
2. Write_timestamp: This field contains the timestamp of the transaction whose new version is created.
3. Read_timestamp: This field contains the timestamp of the transaction of that transaction that will read
that newly created value.
Now let us understand this concept using an example. Let T1 and T2 be two transactions having timestamp
values 15 and 10, respectively.
The transaction T2 calls for a write operation on data (let’s say X) from the database. As T2 calls write operation,
then a new version of data value X is created, which contains the value of X, timestamp of T2, and timestamp of
that transaction which will read X, but in this case, no one is reading the newly created value so that filed
remains empty.

X 10

Now let the transaction T1 (having timestamp 15) call a read operation to read the newly created value X, then
the newly created variable contained will be

X 10 15

Now let’s discuss some important cases:


If timestamp of T2 is less than or equal to timestamp of T1 then
1. Read(X) operation performed by T1: In this case, content of X is returned to T1.
2. Write(X) operation performed by T1: In this case, T1 will be rolled back if timestamp of T1 is smaller than
timestamp of read operation on X. And if timestamp of T1 is equal to the timestamp of write operation on
X then the new version is created again with new contents.
3 Types of Database Failures in DBMS
1. System Crash
Mayday indeed. When the system crashes, it’s a race towards reinstating affected processes or – worse yet –
data recovery.
A system crash usually refers to any kind of bugs or hardware malfunction in the operating system or the
database software. It can bring the processing of transaction to a halt and can even cause the loss of content
residing on volatile storage such as main memory, cache memory, RAM, etc.
There are many reasons why your database system might crash. Maintaining strict security and maintenance
routines and protocols in the database, its host system, and the network should guarantee minimal downtime. In
the event something did happen, the DBA must have a documented crisis plan to restore and reinstate the
database as quickly as possible.
15

2. Media Failure
This one is very risky! Media failures are caused by a head crash or unreadable media. These types of data
failures are considered one of the most serious because it is possible for entire data loss. Media failures usually
leave database systems unavailable for several hours until recovery is complete, especially in applications with
large devices and high transaction volume.
The best way to prevent this type of database failure is to protect your data with adequate malware protection
and backing up your data frequently.
3. Application Software Errors
When the resource limit is exceeded, bad input, logical or internal errors occur, or any other factors related to
the application software is compromised, transactions can fail giving way to database failure.
It is generally recommended that application software errors are minimized in the software code during
conception and the software engineering process. It is better for developers to put mechanisms and controls into
place during the design of the architecture and coding operation, than trying to remedy mistakes later. Asides
from failures, malicious code may exploit known vulnerabilities, especially those associated with a particular
programming software tool or known human software coding error.
Qee.17 explain set operations with example in dbms
SQL set operators are used to combine the results obtained from two or more queries into a single result. The
queries which contain two or more subqueries are known as compounded queries.
There are four major types of SQL operators, namely:
• Union Union all Intersect Minus
Here is an abstract table for whatever we will be learning in this article.

SQL Set Operator Function

Union Combines distinct results of two or more SELECT statements.

Union All Combines all results of two or more SELECT statements, including
duplicates.

Intersect Returns only the common records obtained from two or more SELECT
statements.

Minus Returns only those records which are exclusive to the first table.

Syntax and Parameters of SQL Set Operators


The generic syntax for working with SQL set operators is as follows:
Syntax:
SELECT column_name
FROM table_name_1
SET OPERATOR
16

SELECT column_name
FROM table_name_2
SET OPERATOR
SELECT column_name
FROM table_name_3.
. . .
Parameters:
The different parameters used in the syntax are :
• SET OPERATOR: Mention the type of set operation you want to perform from { Union, Union all, Intersect,
Minus}
• column_name: Mention the column name on which you want to perform the set operation and want in
the result set
• FROM table_name_1: Mention the first table name from which the column has to be fetched
• FROM table_name_2: Mention the second table name from which the column has to be fetched
From the above-mentioned parameters, all the parameters are mandatory. You may use WHERE GROUP BY and
HAVING clauses based on your requirements.
Que.18 explain hash joining working in query in dbms
The name Hash join comes from the hash function(). This hash join is useful for middle to large inputs, but it is
not efficient for every small set. Hash join requires at least one equi join(=), and it supports all joins (left/ right
semi/ anti join). Hash join is the only physical operator that needs memory. Hash join consists of 2 phases.
1. Building or blocking phase
2. Probe or non-blocking phase
How it works
The Hash join is one of the three available joins for joining two tables. However, it is not only about joining. Hash
join is used to find the matching in two tables with a hash table, several joins are available, like nested loop join,
but the hash join is more efficient than the nested loop join.
Build phase
In the first phase, sever creates a hash table in the
memory. In this hash table, rows of the input will be
stored using join. Hash join attributes are used as
hash table keys. This build is called build input. Let’s
assume countries is designated as the build input.
The hash join condition is countries.country_id,
which belongs to the build input. It will be used as
the key in the hash table. Once all the rows are
stored in the hash table, the build phase is completed.

Probe phase
During the probe phase, the server reads rows from the probe input (persons in our illustration). For individual
rows, the server probes the hash table for comparing rows using the value from persons.country_id as the lookup
key. For the particular match, a joined row is sent to the client. In the end, the server scanned each input only
once, using constant time lookup to find matching rows between the two inputs.

You might also like