DBMS
DBMS
Disadvantage of DBMS
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.
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:
2
Types of DBMS 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.
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.
5
Types of Database Languages/SQL Commands
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.
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.
7
the database system. It allows users to grant or revoke privileges to the
database. Here's a list of DCL statements:
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.
The wait for a graph for the above scenario is shown below:
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.
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.
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.
12
There are some points for converting the ER diagram to 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:
14
DELETE vs. TRUNCATE Comparison Chart
The following comparison chart explains their main differences in a quick
manner:
DELETE TRUNCATE
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.
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
19