Databases 2 Course Material
Databases 2 Course Material
Course overview
1) Introduction to database management system (DBMS)
2) Normalization
3) Transactions
4) DBMS languages
5) SQL create database
6) SQL queries
Users
The users have different rights and permissions who use it for different purposes.
Administrators: Maintain the DBMS and are responsible for administrating the database.
They are responsible to look after its usage and by whom it should be used. They create
access profiles for users and apply limitations to maintain isolation and force security.
Administrators also look after DBMS resources like system license, required tools, and
other software and hardware related maintenance.
Designers: A group of people who actually work on the designing part of the database.
They keep a close watch on what data should be kept and in what format. They identify and
design the whole set of entities, relations, constraints, and views.
End Users: Are those who actually reap the benefits of having a DBMS. End users can
range from simple viewers who pay attention to the logs or market rates to sophisticated
users such as business analysts.
Architecture of DBMS
DBMS architecture helps in development, implementation, design, and maintenance of a
database that store and organize information.
It is the base of any database management system, which allows it to perform the functions
effectively and efficiently.
It can be designed as centralized, decentralized, or hierarchical.
The architecture of a DBMS can be seen as either single tier or multi-tier.
1-tier Architecture
In 1-tier architecture, the database is directly available to the DBMS user for executing the SQL
queries and storing data in it. Any changes or updates that are done here will be reflected directly
to the database in the database management system.
Generally, 1-tier architecture is used for the development of applications where a programmer or
developer directly communicates with the database for a quick response.
2-tier Architecture
The 2-tier Architecture of DBMS is based on a client-server machine. In this type of architecture,
applications on the client-side can interact directly with the database at the server-side. For this
interaction between client and the server, application programming interface (API) like Open
Database Connectivity (ODBC) and Java Database Connectivity (JDBC).
This architecture gives poor performance when there are a large number of users at the client
machine to access the database.
3-tier Architecture
The DBMS 3-tier architecture consists of another layer between the client and the server. In this
architecture, the client cannot directly interact with the server. Its features, such as data backup,
recovery, security, and concurrency control make it the most commonly used architecture for
designing the database management system.
The 3-tier architecture consists of the following layers:
Presentation layer: This layer is also known as the client layer. It is the front end layer in
the 3-tier architecture and consists of a user interface. The main purpose of this layer is to
communicate with the application layer.
Application layer: This layer is also known as the business logic layer. It acts as a
middle layer between the client and the database server for exchange of partially
processed data.
Database layer: The data or information is stored in this layer. This layer contains a
method to connect with the database and to perform operations such as insert, update, and
delete.
Normalization
Normalization is an important tool that allows quality database design
Design the most appropriate structures for data
It also derived from the work of Dr. Edgar Codd
It re-organizes the relations based on rules
Why normalize?
Reduces the chance of redundant data
Leads to flexible database design
Allows future changes to structure
Addition of entities, attributes and relationships
Easy insertion, modification and deletion of data
Integrity
Integrity = correctness and consistency of data.
Entity Integrity: In each table, each row has a unique and non-null primary key.
Data Integrity: Every attribute must have correct and meaningful data.
Referential Integrity: Data of one table does not contradict the data in another table.
Transactions
A fundamental mechanism in the DB management.
Is a very small unit of a program.
May contain several low-level tasks.
In a database system must maintain ACID properties.
A major tool in the preservation of integrity and accuracy.
Crucial for multi-users access.
Topic 2 Normalization
Topic 3 Transactions
A fundamental mechanism in the DB management.
Is a very small unit of a program.
May contain several low-level tasks.
In a database system must maintain ACID properties.
A major tool in the preservation of integrity and accuracy.
Crucial for multi-users access.
ACID properties
Atomicity: The property states that a transaction must be treated as an atomic unit, either all or
none of the updates of a transaction are performed.
Consistency: The database must be left in a consistent state when the transaction terminates.
Isolation: Concurrent transactions are kept isolated from each other, no transaction will affect the
existence of any other transaction.
Durability: The database will remain consistent even in the event of a serious failure of the
system, such as loss of power to the computer.
Example:
Operations of transaction
Read Operation: This operation transfers the data item from the database and then stores it in a
buffer in main memory.
Write Operation: This operation writes the updated data value back to the database from the
buffer.
Commit Operation: This operation is used to save the work done permanently in the database.
Commit example
Rollback
The rollback will effectively delete the new rows and correct the updated row.
Concurrency control
Multiple transactions can be executed simultaneously.
Ensure ACID properties.
Decrease waiting time or turnaround time.
Improve response time.
Increased throughput or resource utilization.
The timestamp based protocol. This protocol uses either system time or logical counter as a
timestamp.
Lock-based protocols
Simplistic Lock Protocol
Allow transactions to obtain a lock on every object before a 'write' operation is performed.
Transactions may unlock the data item after completing the ‘write’ operation.
Deadlock Prevention
Deadlocks are caused by the interleaving of lock applications.
This can be avoided by obtaining all required locks at the same time.
If a lock is required later in the transaction, all currently held locks must be initially released.