20 Question DBMS
20 Question DBMS
ANS:-DATABASE MANAGMENT SYSTEM is a collection of interrelated data and a set of programs to access
those data DBMS = Database + Set of programs
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.
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
Conceptual
Level Logical Level
Internal
Level Physical Level
3-tier Architecture
Most widely used architecture is 3-tier architecture.
3-tier architecture separates it tier from each other on basis of users.
application client
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.
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.
query administr
application application tool a -tion
interfaces program tool
application DML
program object compiler and
code organizer
transaction
buffer manager file manager authorization manager
and integrity manager
storage manager
disk storage
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
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
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
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.
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:
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
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
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).
1. One-to-one relationship
A B
A1 B1
A2 B2
A3 B3
A4 B4
customer-name customer-address
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
A1 B1
A2 B2
A3 B3
A4 B4
customer-name customer-address
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
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.
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.
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
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
payment-date
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
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.
Name
Address E-mail
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
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
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
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
Active
Failed Aborted
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
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.
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
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
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 Protocol assumes that a transaction can only be in one of two
phases.
(1) Growing Phase
(2) Shrinking Phase
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
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
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.
*************************************************************************