0% found this document useful (0 votes)
14 views38 pages

20 Question DBMS

The document discusses database management systems and their advantages over traditional file-based systems. It defines DBMS and describes advantages like reduced data redundancy, easier data access, improved data isolation and integrity. It also discusses the responsibilities of a database administrator and the three-tier architecture of database systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views38 pages

20 Question DBMS

The document discusses database management systems and their advantages over traditional file-based systems. It defines DBMS and describes advantages like reduced data redundancy, easier data access, improved data isolation and integrity. It also discusses the responsibilities of a database administrator and the three-tier architecture of database systems.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

CHAPTER-1

INTRODUCTION TO DATABASE SYSTEM

Q.1 DEFINES DBMS. EXPLAINS DISADVANTAGES OF CONVENTIONAL FILE-BASED


SYSTEM COMPARED TO DATABASE MANAGEMENT SYSTEM.
OR

WRITE ADVANTAGE OF DATABASE SYSTEM OVER FILE SYSTEM

ANS:-DATABASE MANAGMENT SYSTEM is a collection of interrelated data and a set of programs to access
those data DBMS = Database + Set of programs

Advantages of DBMS over file System

 Data redundancy and inconsistency


 Difficulty in accessing data
 Data isolation
 Integrity problems
 Atomicity Problems
 Concurrent Access anomalies
 Security problem

 Data redundancy and inconsistency: The same information may be duplicated in several files which is
called redundancy. data inconsistency because various copies of same data.

 Difficulty in accessing data : In the older system if new request come at that time there will be no
application program to meet the request at that time so search manually is time consuming.

 Data isolation: Data is scattered in various files. And files may be in different formats then it is
Difficult to write new application programs to retrieve data.

 Integrity problems: Integrity constraints must be satisfy.

 Atomicity Problems: A computer may failure to ensure that once a failure has occurred and has been
detected, the data is restored to the consistent state that existed before the failure.

 Concurrent Access anomalies: In multi-user systems multiple user the data simultaneously so the
probability of data being in consistent state is more.

 Security problem: Every user of the database must not be able to access all the data
Q.2 What are the Responsibilities of DBA ? Explain three level Data abstraction
also explain database system 3 tier architecture with clear diagram in
detail.
ANS:-The full name of DBA is Database Administrator.
A person in the organization who central control over the system is called Database Administrator

Function of DBA
DBA defines the logical schema of the database.
A schema refers to the overall logical structure of the database.
 Schema definition: The DBA creates the original database schema (structure).
 Schema modification: The DBA modified the schema if necessary.
 Granting of authorization for data access: Granting different types of authorization.
 Backup and Recovery
 Routine maintenance : example of the database administrator’s routine maintenance activities are:
 Periodically backing up the database, ex:- tapes or on remote servers,
 Ensuring that enough free disk space is available.
 Monitoring jobs
 Ensuring that performance is not degraded.

Level of Abstraction

There are three level of abstraction


1) Physical Level OR Internal level
2) Logical Level OR Conceptual level
3) View Level OR External level

External View A View B View C


Level

Conceptual
Level Logical Level

Internal
Level Physical Level

Fig:- Three Level Of Abstraction


 Physical Level/ Internal Level
 Physical representation of the database on the computer.
 The lowest level of abstraction.
 Describes how the data is stored in the database.
 Complex low-level data structures are described in detail.

 Logical Level/Conceptual Level


• The next higher level of abstraction.
• Describes what data is stored in database and relationships among the data.
• The logical level of abstraction is used by database administrator who must decide
what information is to be kept in the database.

 View Level/External Level


• Users’ view of the database.
• This is highest level of abstraction describes only part of the entire database.
• Mostly end users interact with this level most frequently.

3-tier Architecture
Most widely used architecture is 3-tier architecture.
3-tier architecture separates it tier from each other on basis of users.

user Presentation Tier


client

application client

network Application Tier

application server
server
Database Tier
database system

3 tier architecture
Database (Data) Tier
At this tier, only database resides.
Database along with its query processing languages sits in layer-3 of 3-tier architecture.
It also contains all relations and their constraints.
Application (Middle) Tier
At this tier the application server and program, which access database, resides
Database tier is not aware of any other user beyond application tier.
This tier works as mediator between the two.
User (Presentation) Tier
An end user sits on this tier.
At this layer multiple views of database can be provided by the application.
All views are generated by an application, which resides in application tier.

Q.3 Explain Data Independence and Explain different database


users.
Data Independence
Data independency is the ability to modify a schema(structure) definition in one level
without affecting a schema definition in the next higher level.
Types of data independence
1. Physical data independence
2. Logical data independence
1. Physical data independence
The ability to modify or changing in the Physical structure without any changes in
Logical structure is called Physical data independence.
2. Logical data independence
The ability to modify or changing in the Logical structure without any changes in
Physical structure is called Logical data independence.

There are three different database users.


1. Naive User
2. Application programmer
3. Sophisticated User

Naive users
These users are unsophisticated users who have very less knowledge of database system.
These users interact with the system by using one of the application programs that have
been written previously.
Examples, people accessing database over the web, bank tellers, clerical staff etc.
Application programmers
These users are computer professionals who write application programs using some tools.
Sophisticated users
users who good knowledge of database system.
These users interact with system without writing program. They form their request in a
database query language.
Q.4 Explain Database System Architecture.
Components of a DBMS
These functional units of a database system can be divided into two parts:
1. Query Processor Units (Components)
2. Storage Manager Units

Query Processor
Query processor units deal with execution of DDL and DML statements.
DDL Interpreter — Interprets DDL statements into a set of tables
DML Compiler — Translates DML statements into low level instructions that the
query evaluation engine understands.
Query Evaluation Engine — Executes low level instructions generated by DML
compiler.

Storage Manager
Storage manager units provide interface between the low level data stored in database and
the application programs & queries submitted to the system.

File Manager — Manages allocation of space on disk storage.


Buffer Manager — Fetches data from disk storage to memory for being used.
Authorization Manager — Checks the authority of users to access data.
Integrity Manager — Checks for the satisfaction of the integrity constraints.
Transaction Manager — Preserves atomicity and controls concurrency.
Data Files — To store user data.
Data Dictionary and System Catalog — To store metadata.
Indices — To provide faster access to data items.
Statistical Data — To store statistical information about the data in the database. This
information is used by the query processor to select efficient ways to execute a query.
naive users sophisticated database
application users
(tellers, agents, administrator
programmers (analyst)
web-users)
use use
use write

query administr
application application tool a -tion
interfaces program tool

compiler and DDL


DML queries interpreter
linker

application DML
program object compiler and
code organizer

query evaluation Query processor


engine

transaction
buffer manager file manager authorization manager
and integrity manager

storage manager

disk storage

indices data dictionary

data statistical data

Database System Architecture


CHAPTER-2
INTRODUCTION TO DATABASE SYSTEM

Q.5 What is relational algebra? Explain relational algebraic operation.


ANS:-Relational algebra is a language for expressing queries. Relation algebra is a procedural
query language.
Relational Algebra take one table as input and provide one or more
table as output
Relational algebraic operations are as follows:
1. SELECT
2. PROJECT
3. RENAME
4. SET
(A) UNION
(B) INTERSECTION
(C) DIFFERENCE
(D) CARTITION PRODUCT
(E) DIVISION
5. JOIN
(A) NATURAL JOIN
(B) OUTER JOIN
(i) LEFT OUTER
(ii)RIGHT OUTER
(iii)FULL JOIN

1. SELECT:-
Operation: It is used to select particular tuples(row) from a table and discard other rows.
Symbol: σ (Sigma)
Notation: σ(condition) <Table name>
Example: Find out all the students of CE department.
σDept=“CE” (Student)

2. Projection:-
Operation:-It selects particular column and discard other column.
Symbol: ∏ (Pi)
Notation: ∏ (column namet) <Table name>
Example: List out all students with their roll no, name and department name.
∏Rno, Name, Dept (Student)
3. Rename:-
Operation: It is used to rename a table or attributes(column).
Symbol: ρ (Rho)
Notation: ρA(B)Rename relation B to A.
ρA(X1,X2….Xn)(B) Rename relation B to A and its attributes to X1, X2, …., Xn.

3. Cartesian product:-
Operation: Combines information of two relations.
It will multiply each tuples of first relation to each tuples of second relation. It
is also known as Cross product operation and similar to mathematical
Cartesian product operation.
Symbol: X (Cross)
Notation: Relation1 X Relation2
Resultant Relation :
 If relation1 and relation2 have n1 and n2 tuples respectively, then resultant

4. Union
Operation: Selects row from two tables.
Symbol : U(Union)
Notation : Relation1 U Relation2
5. Intersection
Operation: Selects tuples those are in both table.
Symbol : ∩ (Intersection)
Notation : Relation1 ∩ Relation2

6. Difference:-
Operation: Selects tuples those are in first (left) relation but not in second (right)
relation.
Symbol : — (Minus)
Notation : Relation1 — Relation2

7. Division:-
Operation: The result consists of the header of R but not in the header of S, for which it holds
that all the tuples in S are presented in R.
Symbol: ÷
Notation: R ÷ S

Example: Find out all students having both tasks Database1 as well as Database2.
∏(student)(Work) ÷ ∏(Task)(Project)
8. Join:-
Natural Join Operation (⋈)
Operation: Natural join use to combine the row from multiple table and delete
duplicate row .
Notation: Relation1 ⋈ Relation2 Consider following table

9. Outer Join Operation


The outer join operation can be divided into three different forms:
1. Left outer join ( )
2. Right outer join ( )
3. Full outer join ( )

1. Left outer join ( )

The left outer join retains(preserve) all the tuples of the left relation even through there
is no matching tuple in the right relation.

For such kind of tuples having no matching, the attributes of left relation will be fill with
null

Example : College Hostel

2. Right outer join ( )


The Right outer join retains(preserve) all the tuples of the Right relation even through
there is no matching tuple in the Left relation.
For such kind of tuples having
no matching, the attributes of left relation will be fill withnull
Example : College Hostel

3. Full outer join ( )


The full outer join returns all the tuples of both of the relations. It also pads null values
whenever required.

Example : College Hostel


Q.6 Explain Tuple Relational calculus in Detail.

ANS:-A tuple relational calculus is a non-procedural query language which specifies to select the
tuples in a relation. It can select the tuples with range of values

A query in the tuple relational calculus is expressed as

{t | P (t)} or {t | condition (t)}

it is the set of all tuples t such that predicate P is true for t.

Example:-

{t | EMPLOYEE (t) and t.SALARY>10000} - it selects the tuples from EMPLOYEE relation such that
resulting employee tuples will have salary greater than 10000.
{t | EMPLOYEE (t) AND t.DEPT_ID = 10} – it select all the tuples of employee name who work for
Department 10.

1. The variable which is used in the condition is called tuple variable. In above example
t.SALARY and t.DEPT_ID are tuple variables.
2. Any tuple variable with condition is called bound variable. In example SALARY greater than
10000 is bound variable.

Q.7 Explain Domain Relational calculus in Detail.

Ans:- domain relational calculus uses list of attribute to be selected from the relation based on the
condition. It is same as TRC, but differs by selecting the attributes rather than selecting whole tuples. It
is denoted as below:

{< a1, a2, a3, … an > | P(a1, a2, a3, … an)}

Where a1, a2, a3, … an are attributes of the relation and P is the condition.

For example, select EMP_ID and EMP_NAME of employees who work for department 10

{<EMP_ID, EMP_NAME> | <EMP_ID, EMP_NAME> ? EMPLOYEE Λ DEPT_ID = 10}

Get name of the department name that Alex works for.

{DEPT_NAME |< DEPT_NAME > ? DEPT Λ ? DEPT_ID (<DEPT_ID> ? EMPLOYEE Λ EMP_NAME =


Alex)}

Here green color expression is evaluated to get the department Id of Alex and then it is used to get the
department name form DEPT relation.
CHAPTER-3

E-R MODEL

Q.7 Define the following terms. (GTU dec-10, Nov-13)


ANS:- Entity
An entity is a thing or object or person in the real world that is distinguishable from all
other object.
E.g. book, student, employee, college etc…
Entity sets
An entity set is a set of entities of same type that share the same properties or attributes.
E.g. the set of all students in a college can be defined as entity set student.
Relationship
Relationship is an association (connection) between several entities.
Relationship between 2 entities is called binary relationship.
E.g. book is issued by student where book and student are entities and issue is relation.
Relationship set
Relationship set is a set of relationships of the same type.
Attributes
Attributes are properties hold by each member of an entity set.
E.g. entity is student and attributes of students are enrollmentno, name, address, cpi etc

TYPES OF ATTRIBUTES
a. Simple attribute: It cannot be divided into subparts. E.g. cpi, rollno
b. Composite attribute: It can be divided into subparts. E.g. name (first name-middle
name- last name), address.
c. Single valued attribute: It has single data value. E.g. enrollmentno, birthdate
d. Multi valued attribute: It has multiple data value. E.g. phoneno (may have
multiple phones)
e. Derived attribute: It’s value is derived or calculated from other attributes. E.g. age
(can be calculated using current date and birthdate).

Q.8 Explain various mapping cardinality (cardinality constraint).

Mapping cardinality (cardinality constraints)


It represents the number of entities of another entity set which are connected to an entity
using a relationship set.
It is most useful in describing binary relationship sets.
For a binary relationship set the mapping cardinality must be one of the following types:
One to one
One to many
Many to one
Many to many

1. One-to-one relationship
A B

A1 B1

A2 B2

A3 B3

A4 B4

An entity in A is associated with at most (only) one entity in B and an entity in B is


associated with at most (only) one entity in A.

customer-name customer-address

customer-id customer-city loan-no amount

customer borrower loan

FIG:- One to One Relationship


A customer is connected with only one loan using the relationship borrower and a loan is
connected with only one customer using borrower.

2. One-to-many relationship

A B

A1 B1

A2 B2

A3 B3

A4 B4

An entity in A is associated with any number (zero or more) of entities in B and an entity in B is
associated with at most one (only) entity in A.
In the one-to-many relationship a loan is connected with only one customer using borrower and a
customer is connected with more than one loans using borrower.

customer-name customer-address

customer-id customer-city loan-no amount

customer borrower loan


3. Many-to-one relationship
A B

A1 B1

A2 B2

A3 B3

A4 B4

customer-name customer-address

customer-id customer-city loan-no amount

customer borrower loan

In a many-to-one relationship a loan is connected with more than one customer using borrower
and a customer is connected with only one loan using borrower.
4. Many-to-many relationship
A B

A1 B1

A2 B2

A3 B3

A4 B4

An entity in A is associated with any number (zero or more) of entities in B and an entity
in B is associated with any number (zero or more) of entities in A.

customer-name customer-address

customer-id customer-city loan-no amount

customer borrower loan

A customer is connected with more than one loan using borrower and a loan is connected
with more than one customer using borrower.
Q.8 What is E-R model (Entity-Relationship) model (diagram) also draw
various symbols using in E-R diagram. (GTU May-12, May-13)
E-R model
Entity-relationship (ER) diagram is a graphical representation of entities and their
relationships to each other with their attributes.
Q.9 Explain Specialization and Generalization in E-R diagram with example.

Specialization Generalization
It will work in Top-down approach. It will work in Bottom-up approach
The process of creating sub-groupings within an The process of creating groupings from
entity set is called specialization. various entity sets is called generalization.
Specialization is a process of taking a sub set of Generalization is a process of taking the
higher level entity set to form a lower-level union of two or more lower-level entity sets
entity set. to produce a higher-level entity set.
Specialization starts from a single entity set; it Generalization starts from the number of
creates different low-level entity set using some entity sets and creates high-level entity set
different features. using some common features.

For all practical purposes, generalization specialization is inversion of each other.

Specialization
A top-down design process that creates subclasses based on some different characteristics
of the entities in the superclass.
The process of designating sub groupings within an entity set is called
specialization.
An entity set may include sub groupings of entities that are different in some way from
other entities in the set.
A person may be further classified as one of the following:
customer
Employee
The specialization of person allows us to distinguish among persons according to whether
they are employees or customers.
Now again, employees may be further classified as one of the following:
officer
teller
secretary
In terms of an E-R diagram, specialization is depicted by a triangle component labeled
ISA.
The label ISA stands for ―is a‖ and represents, for example, that a customer ―is a‖ person.
The ISA relationship may also be referred to as a superclass subclass relationship.
GENERALIZATION
A bottom-up design process that combines number of entity sets that have same features
into a higher-level entity set.
The design process proceed in a bottom-up manner, in which multiple entity sets are
grouped into a higher level entity set on the basis of common features.
.
Higher level entity set is called superclass and lower level entity set is called subclass. So
the person entity set is the superclass of two subclasses customer and employee.
Differences in the two approaches may be characterized by their starting point and
overall goal.

Specialization and Generalizationn


Q.10 (i)Explain various participation constraints.
(ii) WHAT DO YOU MEAN BY CONSTRAINTS? EXPLAIN TYPES
OF CONSTRAINTS. (GTU May-12, May-13)

Participation constraints
It specifies the participation of an entity set in a relationship set.
There are two types participation constraints
Total participation
Partial participation
Total participation
In total participation every entity in the entity set participates in at least one relationship
in the relationship set.
It specifies that every entity in super class must be member of some of its sub class.
E.g. participation of loan in borrower is total because every loan must be connected to a
customer using borrower.
It is indicated by double line.
Partial participation
In partial participation some entities may not participate in any relationship in the
relationship set.
It specifies that an entity may not belong to any sub class.
E.g. participation of customer in borrower is partial because every customer is not
connected to loan using borrower. It is indicated by single line

customer-name customer-address

customer-id customer-city loan-no amount

customer borrower loan

Partial Participation Total Participation


(ii) WHAT DO YOU MEAN BY CONSTRAINTS? EXPLAIN TYPES OF
CONSTRAINTS. (GTU May-12, May-13)

Constraints are rules which are Apply on data for Restrict entering invalid data into
tables.
Types of constraints
1. Integrity Constraints (Primary Key Constraint)
2. Referential Integrity Constraints (Foreign Key Constraints)
3. Domain Integrity Constraint
(i) Check Constraints
(ii) Null Constraint

1. Integrity Constraints OR (Primary Key Constraint)


a. A primary key is one or more column in a table that is used to uniquely
identify each row in the table
b. The column in which primary key is set cannot be left blank
c. The data stored in the column must be Unique.

2. Referential Integrity OR (FOREIGN KEY Constraint)


a. A Foreign key represents a relationship between tables
b. A foreign key is column or a group of columns whose values are derived from
the primary key of other table
c. Ensure the relationship must preserve as data insert, delete &modify.
d. If an insert or update operation is performed in the foreign table, the
corresponding data value must exist in the primary table, otherwise the
operation is not allowed
e. If a delete operation is performed on the primary table, then the data value
must first be deleted from the foreign table. Otherwise the operation is not
allowed.

3. Domain Integrity Constraint


Ensure data value inside table follow rules for values,range etc.
(i) Check Constraint:- use to limit the value by using operator(<,>,<=,>= etc)
(ii) Null Constraint:- Allow Null value or not NULL value in aq column by using NULL or
NOT NULL keyword.
Q.11 EXPLAIN FOLLOWING WITH EXAMPLE
(i) Weak Entity set and strong Entity set (ii) keys
(iii) Aggregation (iv) Schema, sub schema and Instance

(i) Weak entity set


1. An entity set that does not have a sufficient attribute to create the primary key is called weak
entity set.
2. An entity set that is dependent on other entity set is called weak entity set
3. An entity set on which weak entity set depend is called strong entity set
4. The existence of a weak entity set depends on another entity set called strong entity
set.
5. Weak entity set is shown by double rectangle and weak relationship set is indicated by double
diamond.

payment-date

loan-no amount payment-no loan-amount

loan loan-payment payment

Strong Entity
Weak
Weak Entity Relationship Entity

E.g. in above fig. there are two entities loan and payment in which loan is strong entity set and
payment is weak entity set.
Payment entity must be connected with the Loan entity. If a Loan entity is deleted then its
connected payment entity also deleted.
(ii) Keys
Primary key
A Primary key is a candidate key that is Uniquely identify tuples in a relation.

Candidate key
A Candidate key is an attribute or set of attributes that uniquely identify a tupe from table.
In such case one of the candidate key is choosen as a primary key and remaining candidate
key is called super key.
For example, combination of roll_no and department_name is sufficient to distinguish
one student tuple from another. But either roll_no or department_name alone is not
sufficient to distinguish one student tuple from another. So {roll_no, department_name}
is candidate key.

Super key
A super key is a set of one or more attributes that allow us to identify each tuple uniquely
in a relation.
A Super key are those candidate key that are not selected as a primary key
For example, the enrollment_no, roll_no with department_name of a student is sufficient
to distinguish one student tuple from another. So {enrollment_no} and {roll_no,
department_name} both are super key.
Foreign key
A foreign key is a set of one or more attributes in one table that form a primary key for
another table. another relation.
(iii) Aggregation

The E-R model cannot express relationships among relationships. When


would we need such a thing at that time aggregation is used.
Aggregation is an abstraction through which relationships are treated as higher-level
entities.

Consider a database with information about employees who work on a particular project and
use a
number of machines doing that work

Relationship sets work and uses could be combined into a single set. We can combine
them by using aggregation.

For our example, we treat the relationship set work and the entity sets employee and project as a
higher-level entity set called work.
Transforming an E-R diagram with aggregation into tabular form is easy. We create a
table for each entity and relationship set as before.
The table for relationship set uses contains a column for each attribute in the primary key
of machinery and work.
(ii) Definition

Schema
The overall design of the database is called the database schema.
The logical structure of database
Sub-schema
A database may also have several schemas at the view level, sometimes called subschema.
Instances
The collection of information stored in the database as a particular moment is called an
instance of the database.

Q.12 Explain the steps to reduce the ER diagram to ER database schema.


(GTU Jan-13)

Step 1: Entities and Simple Attributes:


1. An entity type within ER diagram is turned into a table.
2. Each attribute turns into a column (attribute) in the table.
3. It is highly recommended that every table should start with its primary key attribute.
4. the primary key of the table which is usually underlined.
5. The initial relational schema is expressed in the following format writing the table names with
the attributes list inside parentheses as shown below
Persons( personid, name, address, email )
Persons and Phones are Tables and person id, name, address and email are Columns
(Attributes).
Person id is the primary key for the table : Person

PersonID Person Phone

Name
Address E-mail

Step 2: Multi-Valued Attributes


A multi-valued attribute is usually represented with a double-line oval.

Person
PersonID Phone

If you have a multi-valued attribute, take that multi-valued attribute and turn it into a new
entity or table of its own.
Then make a 1:N relationship between the new entity and the existing one.
In simple words.
1. Create a table for that multi-valued attribute.
2. Add the primary (id) column of the parent entity as a foreign key
within the new table as shown below:
First table is Persons ( personid, name, lastname, email )
Second table is Phones ( phoneid , personid, phone )
personid within the table Phones is a foreign key referring to the personid of Persons

Step 3: 1:1 Relationship

WifeID Wife Name

Have

Person
PersonID Phone

Name
E-mail
Email
Address
Let us consider the case where the Person has one wife. You can place the primary key of
the wife table wifeid in the table Persons which we call in this case Foreign key as shown
below.
Persons( personid, name, lastname, email , wifeid )
Wife ( wifeid , name )

Or vice versa to put the personid as a foreign key within the wife table as shown below:
Persons( personid, name, lastname, email )
Wife ( wifeid , name , personid)
For cases when the Person is not married i.e. has no wifeID, the attribute can set to
NULL

Step 4: 1:N Relationships

HouseID House Name

Address
Has

PersonID Person
Phone
Name
Email
Address

For instance, the Person can have a House from zero to many, but a House can have only one
Person.
In such relationship place the primary key attribute of table having 1 mapping in to the table
having many cardinality as a foreign key.
To represent such relationship the personid as the Parent table must be placed within the Child
table as a foreign key.
It should convert to :
Persons( personid, name, address, email )
House ( houseid, name , address, personid)

(IV)Schema
The overall design of the database is called the database schema.
The logical structure of database
Sub-schemaA database may also have several schemas at the view level, sometimes called
subschema.
InstancesThe collection of information stored in the database as a particular moment is
called an instance of the database
CHAPTER-6
TRANSACTION

Q.13 What is transaction? List and explain ACID property of transaction


with example.
Transaction
A transaction is a part of program execution that accesses and updates various data
items.
A transaction can be defined as a group of tasks
A transaction is a logical unit of work
ACID property
Atomicity
Either all operations of the transaction are properly reflected in the database or none
are.
Means either all the operations of a transaction are executed or not a single operation
is executed.
For example consider below transaction to transfer Rs. 50 from account A to account B:
1. read(A)
2. A := A – 50
3. write(A)
4. read(B)
5. B := B + 50
6. write(B)
In above transaction if Rs. 50 is deducted from account A then it must be added to
account B.
Consistency
Execution of a transaction in isolation preserves the consistency of the database.
Means our database must remain in consistent state after execution of any transaction.
In above example total of A and B must remain same before and after the execution of transaction.
Isolation
Although multiple transactions may execute concurrently, each transaction must be
unaware of other concurrently executing transactions.
Intermediate transaction results must be hidden from other concurrently executed
transactions.
In above example once your transaction start from step one its result should not be
access by any other transaction until last step (step 6) is completed.

Durability
After a transaction completes successfully, the changes it has made to the database
persist, even if there are system failures.
Once your transaction completed up to step 6 its result must be stored permanently. It
should not be removed if system fails.
Q.14 Explain different states in transaction processing in database.
OR
Explain State Transition Diagram (Transaction State Diagram).
Because failure of transaction may occur, transaction is broken up into states to
handle various situations.
Following are the different states in transaction processing in database
 Active
 Partial committed
 Failed
 Aborted
 Committed

Partial Committed Commited

Active

Failed Aborted

Fig. State Transition Diagram


Active
This is the initial state. The transaction stays in this state while it is executing.
Partially Committed
This is the state after the final statement of the transaction is executed.
At this point failure is still possible since changes may have been only done in main
memory, a hardware failure could still occur.
After it has written out all the necessary information, it is committed.

Committed
The transaction enters in this state after successful completion of the
transaction. We cannot abort or rollback a committed transaction.
Failed
After the discovery that normal execution can no longer proceed.
Once a transaction cannot be completed, any changes that it made must be undone
rolling it back.
Aborted
The state after the transaction has been rolled back and the database has been
restored to its state prior to the start of the transaction.
Q.15 Explain both the forms of serializability with example. Also explain
relation between two forms.
OR
Explain conflict serializability and view serializability with
example.

Serializability is used to keep the data in the data item in a consistent state.
There are two types of Serializability
(1) Conflict
(2) view
Conflict serializability
Instructions li and lj of transactions Ti and Tj respectively, conflict if and only if there
exists some item Q accessed by both li and lj, and at least one of these instructions
wrote Q.
1. If li and lj access different data item then li and lj don’t conflict.
2. li = read(Q), lj = read(Q). li and lj don’t conflict.
3. li = read(Q), lj = write(Q). li and lj conflict.
4. li = write(Q), lj = read(Q). li and lj conflict.
5. li = write(Q), lj = write(Q). li and lj conflict.
Example
In this example s1 and s2 are both conflict and view serilizable.

In below example the write(A) instruction of transaction T1 conflict with read(A) instruction of
transaction T2 because both the instructions access same data A. But write(A) instruction of
transaction T2 is not conflict with read(B) instruction of transaction T1 because both the
instructions access different data. Transaction T2 performs write operation in A and
transaction T1 is reading B.

Schedule S1 Schedule S2
T1 T2 T1 T2
read(A) read(A)
write(A) write(A)
read(A) read(B)
write(A) write(B)
read(B) read(A)
write(B) write(A)
read(B) read(B)
write(B) write(B)
View serializability
Consider two schedules S1 and S2, they are said to be view equivalent if following conditions
are true :
1. Initial read must be same.
If in S1: transaction Ti reads the initial value of Q, then
in S2: transaction Ti must read the initial value of Q.

2. There are two transactions say Ti and Tj, The schedule S1 and S2 are view
equivalent if:-If in S1: Ti reads A that has been produced by Tj, then in
S2 same should be happen.
3. Final write operations should be same between S1 and S2.
If in S1: Ti does last write on A,
then in S2: Ti also does last write on A

A schedule S is view serializable if it is view equivalent to a serial schedule.


Every conflict serializable schedule is also view serializable but every view
serializable is not conflict serializable.

Q.16 Explain working of two phase commit protocol.


Two phase commit protocol
• The two phase commit protocol provides an automatic recovery mechanism in
case a system or media failure occurs during execution of the transaction.
• The two phase commit protocol ensures that all participants perform the same
action (either to commit or to roll back a transaction).
• The two phase commit strategy is designed to ensure that either all the
databases are updated or none of them, so that the databases remain synchronized.
• In two phase commit protocol there is one node which is act as a coordinator
and all other participating node are known as participant.
• Coordinator – the component that coordinates with all the participants.
• (Participants – each individual node except coordinator are participant.
• As the name suggests, the two phase commit protocol involves two phases.
1. The first phase is Commit Request phase OR phase 1
2. The second phase is Commit decision phase OR phase 2
1. Commit Request Phase
To commit the transaction, the coordinator sends a request asking for “ready for
commit” to each participant.
The coordinator waits until it has received a reply from all participants to “vote” on
the request.
Each participant votes by sending a message back to the coordinator as follows:
 It votes YES if it is prepared to commit
 It may vote NO for any reason if it cannot prepare the transaction due
to a local failure.
 It may delay in voting because cohort was busy with other work.
2. Commit Decision Phase
If the coordinator receives YES response from all participants, it decides to commit.
The transaction is now officially committed. Otherwise, it either receives a NO
response or gives up waiting for some participant, so it decides to abort.
The coordinator sends its decision to all participants (i.e. COMMIT or ABORT).
Participants acknowledge receipt of commit or about by replying DONE.

Q.17 What is system recovery? Explain Log based recovery method.


OR
Explain Deferred Database Modification log based recovery method.

Database recovery is the process of restoring a database to the correct state in the
event of a failure.
Database recovery is a service that is provided by the DBMS to ensure that the
database is reliable and remain in consistent state in case of a failure.

Log based recovery


The log is a sequence records, recording all the update activities in the database. In
short log is a file, which contains history of all transaction.
log contains a complete record of all database activity,

When transaction Ti starts, it registers itself by writing a log record

 <Ti start>. Transaction Ti has started.


 <Ti, Xj, V1, V2> Transaction Ti has performed a write on data item Xj. Xj had
value V1 before write, and will have value V2 after the write.
 < Ti commit> Transaction Ti has committed.
 < Ti abort> Transaction Ti has aborted.

Two approaches are used in log based recovery


1. Deferred Database Modification
2. Immediate Database Modification
1. Deferred Database modification
Updates (changes) to the database are deferred (or postponed) until the transaction
commits.
During the execution of transaction, updates are recorded only in the transaction log.
After the transaction commits, these updates are recorded in the database.

Let T0 be transaction that transfers $50 from account A to account B:


T0: read (A);
A: = A-50;
Write (A);
Read (B);
B: = B + 50;
Write (B).

2. Immediate Database Modification


Concept
Updates (changes) to the database are applied immediately as they occur without
waiting to reach to the commit point.
Also, these updates are recorded in the transaction log.
It is possible here that updates of the uncommitted transaction are also written to
the database. And, other transactions can access these updated values.
Example

Transactions T0 and T1 executed one after the other in the order T0 followed by T1.
The portion of the log containing the relevant information concerning these two
transactions appears in the following,
Portion of the system log corresponding to T0 and T1

Log Immediate Deferred


<T0start>

<T0,A, 1000, 950> A= 950


<To,B, 2000, 2050> B= 2050
<T0 commit> A=950,B=2050
Q,18 Define lock. Explain lock based protocol.
OR
Explain two phase locking. Define strict two phases locking protocol.

Lock
A lock is a variable associated with data item to control concurrent access to that data
item.
A lock is a mechanism to control concurrent access to a data item

Lock based protocol


Data items can be locked in two modes

1. Shared (S) mode. Data item can only be read.


S-lock is requested using lock-S instruction.
2. Exclusive (X) mode. Data item can be both read as well as written.
X-lock is requested using lock-X instruction.

1. Lock requests are made to concurrency-control manager. Transaction can proceed only after
request is granted.
2. A transaction may be granted a lock on an item if the requested lock is compatible with
locks already held on the item by other transactions Any number of transactions can hold
shared locks on an item, but if any transaction holds an exclusive on the item no other
transaction may hold any lock on the item.
3. If a lock cannot be granted, the requesting transaction is made to wait till all incompatible
locks held by other transactions have been released. The lock is then granted.

Two phase locking


The Two Phase Locking Protocol defines the rules of how to acquire the locks on a
data item and how to release the locks.
Two phase locking (2PL) is a concurrency control method that guarantees serializability.

Two Phase Locking Protocol assumes that a transaction can only be in one of two
phases.
(1) Growing Phase
(2) Shrinking Phase

Phase 1 - Growing Phase


1. In this phase the transaction can only acquire locks, but cannot release
any lock.
2. The transaction enters the growing phase as soon as it acquires the first
lock it wants.
3. From now on it has no option but to keep acquiring all the locks it would
need.
4. It cannot release any lock at this phase even if it has finished working
with a locked data item.
5. Ultimately the transaction reaches a point where all the lock it may
need has been acquired. This point is called Lock Point.
Phase 2 - Shrinking Phase
1. After Lock Point has been reached, the transaction enters the shrinking phase.
2. In this phase the transaction can only release locks, but cannot acquire any new
lock.
3. The transaction enters the shrinking phase as soon as it releases the first lock
after crossing the Lock Point.
4. From now on it has no option but to keep releasing all the acquired locks.
5. Initially the transaction is in growing phase, that is the transaction acquires
locks as needed.
Once the transaction releases lock, it enters the shrinking phase and no more lock
request may be issued.
Strict Two Phase Locking Protocol
In this protocol, a transaction may release all the shared locks after the Lock Point has
been reached, but it cannot release any of the exclusive locks until the transaction
commits or aborts.
This ensures that any data is written by an uncommitted transaction are locked in
exclusive mode until the transaction commits and preventing other transaction from
reading that data.

Q.19 Explain time stamp based protocol.


Time stamp based protocol
This protocol uses either system time or logical counter to be used as a time-stamp.
Every transaction has a time-stamp associated with it and the ordering is determined
by the age of the transaction.
A transaction created at 0002 clock time would be older than all other transaction,
which come after it.
For example, any transaction 'y' entering the system at 0004 is two seconds younger
and priority may be given to the older one.
1. Time-stamp of Transaction Ti is denoted as TS(Ti).
2. Read time-stamp of data-item X is denoted by R-timestamp(X).
3. Write time-stamp of data-item X is denoted by W-
timestamp(X).

Timestamp ordering protocol works as follows:


If a transaction Ti issues read(X) operation:
If TS(Ti) < W-timestamp(X)
 Operation rejected.
If TS(Ti) >= W-timestamp(X)
 Operation executed.
All data-item Timestamps updated.

If a transaction Ti issues write(X) operation:


(3) If TS(Ti) < R-timestamp(X)
 Operation rejected.
(4) If TS(Ti) < W-timestamp(X)
 Operation rejected and Ti rolled back.
(5) Otherwise, operation executed.

Q.20 Define deadlock. Explain wait-for-graph. Explain different


conditions that lead to deadlock.
OR
Explain deadlock detection. Explain Resource-Allocation Graph.

OR
Explain methods to prevent deadlock.
Deadlock
A deadlock is a condition when two or more transactions are executing and each
transaction is waiting for the other to finish but none of them are ever finished. So all
the transactions will wait for infinite time and not a single transaction is completed.

Wait-for-graph

Table 1
Held by Wait for

Transaction 1 Transaction 2

Wait for Table 2 Hold by

In the above figure there are two transactions 1 and 2 and two table’s as table1 and
table 2.
Transaction 1 hold table 1 and wait for table 2. Transaction 2 hold table 2 and wait for
table 1.
Now the table 1 is wanted by transaction 2 and that is hold by transaction 1 and same
way table 2 is wanted by transaction 1 and that is hold by transaction 2. Until any one
can’t get this table they can’t precede further so this is called wait for graph. Because
both of these transaction have to wait for some resources.
When dead lock occurs
Deadlock can occur in any system that satisfies the four conditions:
1. Mutual Exclusion Condition: only one process at a time can use a
resource or each resource assigned to 1 process or is available.
2. Hold and Wait Condition: processes already holding resources may
request new resources.
3. No Preemption Condition: only a process holding a resource can release
it voluntarily after that process has completed its task or previously granted
resources cannot forcibly taken away from any process.
4. Circular Wait Condition: two or more processes forms circular chain
where each process requests a resource that the next process in the chain
holds.
Deadlock detection.
Resource-Allocation Graph
A resource allocation graph tracks which resource is held by which process and which process is
waiting for a resource of a particular type. If a process is using a resource, an arrow is drawn from the
resource node to the process node. If a process is requesting a resource, an arrow is drawn from the
process node to the resource node.
If there is a cycle in the Resource Allocation Graph then the processes will deadlock.
A set of vertices V and a set of edges E.
V is partitioned into two types:
(1)P = {P1, P2, …, Pn}, the set of processes.
(2)R = {R1, R2, …, Rm}, the set of resource.
request edge – directed edge Pi → Rj
assignment edge – directed edge Rj →pi
Pi Process -

Resource –
Process Pi requests resource Rj
If graph contains no cycles then no deadlock. If graph contains cycles then
deadlock.

R1 R3 R1 R3

P1 P2 P3 P1 P2 P3

R2 R4 R2 R4

No cycle (circular chain) created Cycle (circular chain) created


So no deadlock (P2, R3, P3, R4, P2) So deadlock
Deadlock prevention
Deadlock can be prevented by stopping one of the four conditions from occurring
that lead to deadlock.
1. Mutual Exclusion Condition: Removing the mutual exclusion condition
means that no process will have exclusive access (rights) to a resource.
2. Hold and Wait Condition: The hold and wait or resource holding
conditions may be removed by requiring processes to request all the
resources they will need before it begins execution.
3. No Preemption Condition: If a process that is holding some resources
requests another resource that cannot be immediately allocated to it, then all
resources currently being held are released.
4. Circular Wait Condition: avoid circular waits .

Q.21 Explain Shadow Paging Technique.

During the execution of the transaction, two page tables are maintained.
1. Current Page Table: Used to access data items during transaction
execution.
2. Shadow Page Table: Original page table, and will not get modified
during transaction execution.
1. At the start of the transaction, both tables are same and point· to same pages.
2. The shadow page table is never changed, and is used to restore the database in case
of any failure occurs.
3. current page table entries may change during transaction execution.
4. When the transaction completes, the current page table becomes shadow page
table. At this time, it is considered that the transaction has committed.

*************************************************************************

You might also like