Database Management System
Database Management System
ODD SEMESTER-2022
DBMS LAB
(BCA-305)
SUBMITTED FOR
BACHELORS OF COMPUTER APPLICATIONS
SUBMITTED BY SUBMITTED TO
Functions of DBA
Creating and maintaining database standards and policies
Supporting database design, creation, and testing activities
Managing the database availability and performance, including incident and
problem management
Administering database objects to achieve optimum utilization
Defining and implementing event triggers that will alert on potential database
performance or integrity issues
Performing database housekeeping, such as tuning, indexing, etc.
Monitoring usage, transaction volumes, response times, concurrency levels, etc.
Identifying reporting, and managing database security issues, audit trails, and
forensics
Designing database backup, archiving, and storage strategy
Database Schema
It describes the organisation of data and relationships within the database. The design
of the database is called Schema. It represents a logical view of database.
Database Instance
The data stored in the database at a particular moment of time is called Instance of a
Database. As we know, Database Schema defines the attributes in the tables that
belongs to a particular Database. The values of these attributes at a moment of time is
called the Instance of Database.
2 Information Rule
All the data or information in DBMS is to be represented as stored data in the cells of
table. The rows and columns have to be unordered.
3 Guarantee Access Rule
Each unit peace of data should be accessible by primary key (rows) + table name+
attributes (columns).
NULL has several meanings; it can be a missing data, not applicable or no values. It
should be handled consistently. And primary key cannot be NULL.
9 Logical Independence
It states that logical data in database must be independent to its users.
11 Distribution Independence
The end user must not be able to see the data that is distributes over the network
through the locations.
12 Non-Subversion
It states that system has an interface that provides access to low level records then
interface must not be able to subvert system and bypass security and integrity
constraints.
R(x)
W(y)
R(z)
W(z)
Q-7 Explain checkpoint in DBMS recovery.
A checkpoint is used to declare a point before which DBMS was in consistent state and
all transaction work committed.
During transaction execution, such checkpoints are traced. After execution, transaction
log files will be created.
Upon reaching the savepoint/checkpoint, the log file is destroyed by saving its update to
the database. Then a new log is created with upcoming execution operations of the
transaction and it will be updated until the next checkpoint and the process continues.
Whenever transaction logs are created in a real-time environment, it eats up lots of
storage space. Also keeping track of every update and its maintenance may increase
the physical space of the system. Eventually, the transaction log file may not be
handled as the size keeps growing. This can be addressed with checkpoints. The
methodology utilized for removing all previous transaction logs and storing them in
permanent storage is called a Checkpoint.
T1 T2 T3
R(x)
W(x)
R(a)
R(a)
W(y)
R(a)
Transaction Lifecycle
1) Once a transaction states execution, it becomes active. It can issue read and
write operation.
2) Once a read and write operation is complete has completed the transaction
becomes partially committed state.
3) If the check is success, the transaction commits and enters into a committed
state.
4) If the check is failed, the transaction goes to a failed state.
5) If the transaction is aborted in an active state, then it goes into a failed state.
The transaction should be rolled back to undo the effects of its write operation
on the Database.
6) The terminate state refers to the transaction leaving the system.
Q-9 Differentiate between DDL, DML, DCL and TCL Commands.
Deadlock Avoidance –
When a database is stuck in a deadlock, It is always better to avoid the deadlock rather
than restarting or aborting the database. The deadlock avoidance method is suitable for
smaller databases whereas the deadlock prevention method is suitable for larger
databases.
One method of avoiding deadlock is using application-consistent logic. In the above-
given example, Transactions that access Students and Grades should always access
the tables in the same order. In this way, in the scenario described above, Transaction
T1 simply waits for transaction T2 to release the lock on Grades before it begins. When
transaction T2 releases the lock, Transaction T1 can proceed freely.
Another method for avoiding deadlock is to apply both row-level locking mechanism and
READ COMMITTED isolation level. However, It does not guarantee to remove
deadlocks completely.
Deadlock Detection –
When a transaction waits indefinitely to obtain a lock, The database management
system should detect whether the transaction is involved in a deadlock or not.
Wait-for-graph is one of the methods for detecting the deadlock situation. This
method is suitable for smaller databases. In this method, a graph is drawn based
on the transaction and their lock on the resource. If the graph created has a
closed-loop or a cycle, then there is a deadlock.
Deadlock prevention –
For a large database, the deadlock prevention method is suitable. A deadlock can be
prevented if the resources are allocated in such a way that deadlock never occurs. The
DBMS analyzes the operations whether they can create a deadlock situation or not, If
they do, that transaction is never allowed to be executed.
Deadlock prevention mechanism proposes two schemes:
Wait-Die Scheme –
In this scheme, If a transaction requests a resource that is locked by another
transaction, then the DBMS simply checks the timestamp of both transactions
and allows the older transaction to wait until the resource is available for
execution.
A- Atomicity
C- Consistency
I- Isolation
D- Durability
In DBMS, data is the integral part of a database. Each and every database should
follow ACID property to maintain the integrity of the data.
Atomicity-
The term Atomicity defines that the data remains atomic in nature. It means that if any
operation is performed in the data, either it should be executed or should not be
executed at all.
Consistency-
The word Consistency means that the value should be reserved in the database.
Isolation-
The term Isolation means separation. In DBMS Isolation property of database states
that only necessary features are being stored and unnecessary features are hidden.
Durability-
The term Durability means permanency in the database. In Durability, operations are
successfully executed and becomes permanent in the database.
Q- 12 What are joins? What are the types of joins with SQL command?
A JOIN is a SQL command that combines rows from two or more tables based on a
related column between them.
There are several types of JOINs in SQL:
1) INNER JOIN: An INNER JOIN returns only the rows that match the join condition
in both tables. It is the most commonly used type of JOIN. The syntax for an
INNER JOIN is as follows:
SELECT *
FROM table1
INNER JOIN table2
ON table1.common_column = table2.common_column;
2) LEFT JOIN: A LEFT JOIN returns all rows from the left table, and any matching
rows from the right table. If there is no match, NULL values are returned for the
right table's columns. The syntax for a LEFT JOIN is as follows:
SELECT *
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column;
3) RIGHT JOIN: A RIGHT JOIN is similar to a LEFT JOIN, but it returns all rows
from the right table and any matching rows from the left table. If there is no
match, NULL values are returned for the left table's columns. The syntax for a
RIGHT JOIN is as follows:
SELECT *
FROM table1
RIGHT JOIN table2
ON table1.common_column = table2.common_column;
4) FULL OUTER JOIN: A FULL OUTER JOIN returns all rows from both tables,
whether or not there is a match in the other table. If there is no match, NULL
values are returned for the missing columns. The syntax for a FULL OUTER
JOIN is as follows:
SELECT *
FROM table1
FULL OUTER JOIN table2
ON table1.common_column = table2.common_column;
5) CROSS JOIN: A CROSS JOIN returns the Cartesian product of two tables,
which is the number of rows in the first table multiplied by the number of rows in
the second table. A CROSS JOIN does not require a join condition, as it returns
every possible combination of rows from both tables. The syntax for a CROSS
JOIN is as follows:
SELECT *
FROM table1
CROSS JOIN table2;
It is important to note that JOINs can also be combined with WHERE clauses to further
filter the results. For example, you can use a LEFT JOIN and a WHERE clause to return
only the rows that match the join condition in the left table and NULL values for the right
table's columns, as shown below:
C
SELECT *
FROM table1
LEFT JOIN table2
ON table1.common_column = table2.common_column
WHERE table2.common_column IS NULL;
2. Hold and Wait: When the two people refuse to retreat and hold their ground, it is
called holding. This is the next necessary condition for deadlock.
3. No Preemption: For resolving the deadlock one can simply cancel one of the
processes for other to continue. But the Operating System doesn’t do so. It
allocates the resources to the processors for as much time as is needed until the
task is completed. Hence, there is no temporary reallocation of the resources. It is
the third condition for deadlock.
4. Circular Wait: When the two people refuse to retreat and wait for each other to
retreat so that they can complete their task, it is called circular wait. It is the last
condition for deadlock to occur.
Note: All four conditions are necessary for deadlock to occur. If any single one is
prevented or resolved, the deadlock is resolved.
5) Credit card exchanges –
The database Management framework is utilized for buying on charge cards and
age of month to month proclamations.
6) Social Media Sites –
We all utilization of online media sites to associate with companions and to
impart our perspectives to the world. Every day, many people group pursue
these online media accounts like Pinterest, Facebook, Twitter, and Google in
addition to. By the utilization of the data set administration framework, all the data
of clients are put away in the information base and, we become ready to interface
with others.
7) Broadcast communications –
Without DBMS any media transmission organization can’t think. The Database
the executive’s framework is fundamental for these organizations to store the call
subtleties and month to month postpaid bills in the information base.
8) Account –
The information base administration framework is utilized for putting away data
about deals, holding and acquisition of monetary instruments, for example,
stocks and bonds in a data set.
9) Online Shopping –
These days, web-based shopping has become a major pattern. Nobody needs to
visit the shop and burn through their time. Everybody needs to shop through web
based shopping sites, (for example, Amazon, Flipkart, Snapdeal) from home. So
all the items are sold and added uniquely with the assistance of the information
base administration framework (DBMS). Receipt charges, installments, buy data
these are finished with the assistance of DBMS.
10)Human Resource Management –
Big firms or organizations have numerous specialists or representatives working
under them. They store data about worker’s compensation, assessment, and
work with the assistance of an information base administration framework
(DBMS).
21. What is deadlock Prevention? Explain deadlock prevention conditions
Deadlock Prevention
We can prevent Deadlock by eliminating any of the four conditions.
1) Eliminate Mutual Exclusion
It is not possible to dis-satisfy the mutual exclusion because some resources, such as
the tape drive and printer, are inherently non-shareable.
2) Eliminate Hold and wait
Allocate all required resources to the process before the start of its execution, this way
hold and wait condition is eliminated but it will lead to low device utilization. for example,
if a process requires printer at a later time and we have allocated printer before the start
of its execution printer will remain blocked till it has completed its execution.
The process will make a new request for resources after releasing the current set of
resources. This solution may lead to starvation.
3) Eliminate No Preemption
Preempt resources from the process when resources required by other high priority
processes.
4) Eliminate Circular Wait
Each resource will be assigned with a numerical number. A process can request the
resources increasing/decreasing. order of numbering.
For Example, if P1 process is allocated R5 resources, now next time if P1 ask for R4,
R3 lesser than R5 such request will not be granted, only request for resources more
than R5 will be granted.