0% found this document useful (0 votes)
7 views19 pages

DBMS

The document discusses the disadvantages of Database Management Systems (DBMS), including high costs, complexity, and risks of data loss. It explains the structure and components of Relational Database Management Systems (RDBMS), detailing types of database architectures and SQL commands. Additionally, it covers transaction states, deadlock detection and prevention, and concurrency control in databases.
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)
7 views19 pages

DBMS

The document discusses the disadvantages of Database Management Systems (DBMS), including high costs, complexity, and risks of data loss. It explains the structure and components of Relational Database Management Systems (RDBMS), detailing types of database architectures and SQL commands. Additionally, it covers transaction states, deadlock detection and prevention, and concurrency control in databases.
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/ 19

DBMS

Disadvantage of DBMS

o Cost of Hardware and Software: It requires a high speed of data


processor and large memory size to run DBMS software.
o Size: It occupies a large space of disks and large memory to run them
efficiently.
o Complexity: Database system creates additional complexity and
requirements.
o Higher impact of failure: Failure is highly impacted the database
because in most of the organization, all the data stored in a single
database and if the database is damaged due to electric failure or
database corruption then the data may be lost forever.

RDBMS (Relational Database Management System)


The word RDBMS is termed as 'Relational Database Management System.'

This database is based on the relational data model, which stores data in the form of
rows(tuple) and columns(attributes), and together forms a table(relation). A
relational database uses SQL for storing, manipulating, as well as maintaining the
data.

A relational database contains the following components:

o Table
o Record/ Tuple
o Field/Column name /Attribute
o Instance
o Schema

1
o Keys

An RDBMS is a tabular DBMS that maintains the security, integrity, accuracy, and
consistency of the data

What is table/Relation?
Everything in a relational database is stored in the form of relations. The
RDBMS database uses tables to store data. A table is a collection of reJlated
data entries and contains rows and columns to store data.

Properties of a Relation:

o Each relation has a unique name by which it is identified in the database.


o Relation does not contain duplicate tuples.
o The tuples of a relation have no specific order.
o All attributes in a relation are atomic, i.e., each cell of a relation contains
exactly one value.

2
Types of DBMS Architecture

Database architecture can be seen as a single tier or multi-tier. But logically,


database architecture is of two types like: 2-tier architecture and 3-tier
architecture.

1-Tier Architecture
o In this architecture, the database is directly available to the user. It
means the user can directly sit on the DBMS and uses it.
o Any changes done here will directly be done on the database itself. It
doesn't provide a handy tool for end users.
o The 1-Tier architecture is used for development of the local application,
where programmers can directly communicate with the database for the
quick response.

3
2-Tier Architecture
o The 2-Tier architecture is same as basic client-server. In the two-tier
architecture, applications on the client end can directly communicate
with the database at the server side. For this interaction, API's
like: ODBC, JDBC are used.
o The user interfaces and application programs are run on the client-side.
o The server side is responsible to provide the functionalities like: query
processing and transaction management.
o To communicate with the DBMS, client-side application establishes a
connection with the server side.

Fig: 2-tier Architecture

4
3-Tier Architecture
o The 3-Tier architecture contains another layer between the client and
server. In this architecture, client can't directly communicate with the
server.
o The application on the client-end interacts with an application server
which further communicates with the database system.
o End user has no idea about the existence of the database beyond the
application server. The database also has no idea about any other user
beyond the application.
o The 3-Tier architecture is used in case of large web application.

Fig: 3-tier Architecture

5
Types of Database Languages/SQL Commands

1. Data Definition Language (DDL)


o DDL stands for Data Definition Language. It is used to define database
structure or pattern.
o It is used to create schema, tables, indexes, constraints, etc. in the
database.
o Data definition language is used to store the information of metadata
like the number of tables and schemas, their names, indexes, columns in
each table, constraints, etc.
o All DDL commands are auto-committed. That means it saves all the
changes permanently in the database.

Here are some tasks that come under DDL:

o Create: To create new table or database.

6
o Alter: It is used to alter the structure of the database.
o Drop: It is used to delete tables from the database.
o Truncate: It is used to remove all records from a table.
o Rename: It is used to rename a table.

These commands are used to update the database schema that's why they
come under Data definition language.

2. Data Manipulation Language (DML)


DML stands for Data Manipulation Language. It is used for accessing and
manipulating data in a database. It handles user requests.

DML commands are not auto-committed. It means changes are not


permanent to database, they can be rolled back.

Here are some tasks that come under DML:

o Select: It is used to retrieve data from a database (this is under DQL ->
Data Query Language).
o Insert: It is used to insert data into a table.
o Update: It is used to update existing data within a table.
o Delete: It is used to delete all records from a table.
o Merge: It performs UPSERT operation, i.e., insert or update operations.
o Call: It is used to call a structured query language or a Java subprogram.
o Explain Plan: It has the parameter of explaining data.
o Lock Table: It controls concurrency.

3. Data Control Language (DCL)


Data control language (DCL) controls access to the data that users store within
a database. Essentially, this language controls the rights and permissions of

7
the database system. It allows users to grant or revoke privileges to the
database. Here's a list of DCL statements:

 GRANT: Gives a user access to the database


 REVOKE: Removes a user's access to the database

4. Transaction Control Language (TCL)


Transaction control language (TCL) manages the transactions within a
database. Transactions group a set of related tasks into a single, executable
task. All the tasks must succeed in order for the transaction to work. Here's a
list of TCL statements:

Here are some tasks that come under TCL:

o Commit: It is used to save the transaction on the database.


o Rollback: It is used to restore the database to original since the last
Commit.

8
Deadlock Detection
In a database, when a transaction waits indefinitely to obtain a lock, then the
DBMS should detect whether the transaction is involved in a deadlock or not.
The lock manager maintains a Wait for the graph to detect the deadlock cycle
in the database.

Wait for Graph


o This is the suitable method for deadlock detection. In this method, a
graph is created based on the transaction and their lock. If the created
graph has a cycle or closed loop, then there is a deadlock.

The wait for a graph for the above scenario is shown below:

What is Deadlock Prevention?


A deadlock prevention method assures that at least one of the four deadlock
conditions never occurs.

9
What is Deadlock Avoidance?
A system is considered safe when all processes may be assigned resources in
any order without causing a deadlock. The deadlock avoidance mechanism
prevents the system from coming to an unsafe state.

The Banker's algorithm is the most widely used mechanism to avoid


deadlock.

Key differences between Deadlock Prevention


and Deadlock Avoidance
1. A deadlock prevention method assures that at least one of the four
deadlock conditions never occurs. In contrast, the deadlock avoidance
mechanism prevents the system from coming to an unsafe state.
2. The knowledge of future process resource requirements is not required
for deadlock prevention. On the other hand, deadlock avoidance
necessitates an understanding of future process resource requests.
3. There are some algorithms in deadlock prevention, including Non-
blocking synchronization and serializing tokens algorithms. On the
other hand, the most widely used algorithm in deadlock avoidance is
Banker's algorithm.
4. Preemption is more common in deadlock prevention. In contrast,
deadlock avoidance doesn't involve preemption.
5. A conservative resource allocation method is used to prevent deadlock.
In contrast, the technique for allocating resources to avoid deadlock is
not conservative.

10
Deadlock Avoidance:
Deadlock can be avoided if resources are allocated in such a way that it avoids
the deadlock occurrence. Two algorithms for deadlock avoidance:

Wait-Die scheme
In this scheme, if a transaction requests for a resource which is already held
with a conflicting lock by another transaction then the DBMS simply checks
the timestamp of both transactions.

Let's assume there are two transactions Ti and Tj and let TS(T) is a timestamp
of any transaction T.

1. Check if TS(Ti) < TS(Tj) - If Ti is the older transaction and Tj has held
some resource, then Ti is allowed to wait until the data-item is available
for execution. That means if the older transaction is waiting for a
resource which is locked by the younger transaction, then the older
transaction is allowed to wait for resource until it is available.
2. Check if TS(Ti) < TS(Tj) - If Ti is older transaction and has held some
resource and if Tj is waiting for it, then Tj is killed and restarted later with
the random delay but with the same timestamp.

Wound wait scheme


o In wound wait scheme, if the older transaction requests for a resource
which is held by the younger transaction, then older transaction forces
younger one to kill the transaction and release the resource. After the
minute delay, the younger transaction is restarted but with the same
timestamp.
o If the older transaction has held a resource which is requested by the
Younger transaction, then the younger transaction is asked to wait until
older releases it.

11
Reduction of ER diagram to Table
The database can be represented using the notations, and these notations can
be reduced to a collection of tables.

In the database, every entity set or relationship set can be represented in


tabular form.

The ER diagram is given below:

12
There are some points for converting the ER diagram to the table:

o Entity type becomes a table.

In the given ER diagram, LECTURE, STUDENT, SUBJECT and COURSE forms


individual tables.

o All single-valued attribute becomes a column for the table.

In the STUDENT entity, STUDENT_NAME and STUDENT_ID form the column of


STUDENT table. Similarly, COURSE_NAME and COURSE_ID form the column of
COURSE table and so on.

o A key attribute of the entity type represented by the primary key.

In the given ER diagram, COURSE_ID, STUDENT_ID, SUBJECT_ID, and


LECTURE_ID are the key attribute of the entity.

o The multivalued attribute is represented by a separate table.

In the student table, a hobby is a multivalued attribute. So it is not possible to


represent multiple values in a single column of STUDENT table. Hence we
create a table STUD_HOBBY with column name STUDENT_ID and HOBBY.
Using both the column, we create a composite key.

o Composite attribute represented by components.

In the given ER diagram, student address is a composite attribute. It contains


CITY, PIN, DOOR#, STREET, and STATE. In the STUDENT table, these attributes
can merge as an individual column.

o Derived attributes are not considered in the table.

In the STUDENT table, Age is the derived attribute. It can be calculated at any
point of time by calculating the difference between current date and Date of
Birth.

13
Using these rules, you can convert the ER diagram to tables and columns and
assign the mapping between the tables. Table structure for the given ER
diagram is as below:

Figure: Table structure

14
DELETE vs. TRUNCATE Comparison Chart
The following comparison chart explains their main differences in a quick
manner:

DELETE TRUNCATE

The delete statement is used to The truncate command removes the


remove single or multiple records complete data from an existing table
from an existing table depending on but not the table itself. It preserves the
the specified condition. table structure or schema.

It is a DML (Data Manipulation It is a DDL (Data Definition Language)


Language) command. command.

It can use the WHERE clause to filter It does not use the WHERE clause to
any specific row or data from the filter records from the table.
table.

This command eliminates records This command deletes the entire data
one by one. page containing the records.

It locks the table row It locks the entire table

Its speed is slow Its execution is fast.

Syntax: Syntax:
1. Delete from tablename Truncate table tablename
2. Delete from tablename where
columnname = condition

15
Difference between primary key and
unique key:
Primary Key Unique Key
1. Primay key can not accept null 1. Uniqye key can accept only one null
value value.
2. We can have only one primary 2. We can have more than one unique
key in a table. key.
3. Primary key supports auto- 3. Unique key does not support auto
increment value. increment value.
4. Creates clustered index. 4. Creates non-clustered index.

States of Transaction
In a database, the transaction can be in one of the following states -

16
Active state
o The active state is the first state of every transaction. In this state, the
transaction is being executed.
o For example: Insertion or deletion or updating a record is done here. But
all the records are still not saved to the database.

Partially committed
o In the partially committed state, a transaction executes its final
operation, but the data is still not saved to the database.
o In the total mark calculation example, a final display of the total marks
step is executed in this state.

Committed
A transaction is said to be in a committed state if it executes all its operations
successfully. In this state, all the effects are now permanently saved on the
database system.

Failed state
o If any of the checks made by the database recovery system fails, then
the transaction is said to be in the failed state.
o In the example of total mark calculation, if the database is not able to
fire a query to fetch the marks, then the transaction will fail to execute.

Aborted
o If any of the checks fail and the transaction has reached a failed state
then the database recovery system will make sure that the database is in
its previous consistent state. If not then it will abort or roll back the
transaction to bring the database into a consistent state.

17
o If the transaction fails in the middle of the transaction then before
executing the transaction, all the executed transactions are rolled back
to its consistent state.
o After aborting the transaction, the database recovery module will select
one of the two operations:
1. Re-start the transaction
2. Kill the transaction

DBMS Concurrency Control


Concurrency Control is the working concept that is required for controlling
and managing the concurrent execution of database operations and thus
avoiding the inconsistencies in the database.

But before knowing about concurrency control, we should know about


concurrent execution.

Concurrent Execution in DBMS


o In a multi-user system, multiple users can access and use the same
database at one time, which is known as the concurrent execution of the
database. It means that the same database is executed simultaneously
on a multi-user system by different users.
o While working on the database transactions, there occurs the
requirement of using the database by multiple users for performing
different operations, and in that case, concurrent execution of the
database is performed.
o The thing is that the simultaneous execution that is performed should
be done in an interleaved manner, and no operation should affect the
other executing operations, thus maintaining the consistency of the
18
database. Thus, on making the concurrent execution of the transaction
operations, there occur several challenging problems that need to be
solved.

19

You might also like