DBMS Cheatsheet Withlinks Compressed
DBMS Cheatsheet Withlinks Compressed
DBMS Cheatsheet Withlinks Compressed
DATABASE
MANAGEMENT SYSTEM
<...>/<...>
Connect with Alumni
What is DBMS?
Efficient Data
Data Independence
Management
Database Applications
Purpose of
Database Systems Database Management
Systems
Database
Query and
Data Independence
Transaction Support
02 DBMS Cheatsheet
Concurrent Access
and Multi-User
Support
Database Performance
Maintainance Overheads
Efficient Data Data Security
Retrieval
Data
Independence
03 DBMS Cheatsheet
Factual Information
Observations
Data
Values & Figures
Database + DBMS
04 DBMS Cheatsheet
A Data Schema is a blueprint that
defines the structure, organization,
Users
and relationships of data stored in a
database. It provides a framework for
representing and storing information
Database Management
Systems in a systematic way.
Importance of
Data Schemas
Facilitates easier
Enforces data accuracy
maintainance and
and consistency
scalability
05 DBMS Cheatsheet
Types of Data Schemas
06 DBMS Cheatsheet
NoSQL DBMS
NoSQL DMBS
semi-structured data.
07 DBMS Cheatsheet
2 Entity Relationships
Component Symbol
Entity
Relationships
Attribute
08 DBMS Cheatsheet
Cardinality in ERD
Each record in the first entity Each record in the first entity Each record in the first entity
corresponds to exactly one can have many related records can be related to many
record in the second entity, in the second entity corresponds records in the second entity,
and vice versa. to only one record in the and vice versa.
first entity.
Department
Each department can have many employees, but
Each employee has exactly one passport, & each each employee belongs to only one department.
passport is associated with exactly one employee
Example : Many-to-Many
Student Course
Student_ID Course_ID
Name Course_Name
Grade
09 DBMS Cheatsheet
3 Keys in DBMS
A unique identifier for each record in an entity, A field in one table that links to the primary key
often depicted in ERD as underlined attributes). in another table, establishing relationships
between entities.
Example:
Employee Department
Name Department_Name
Relationship: Employee.Department_ID
Department.Department_ID
Composite Key
A composite key consists of two or more columns that, together, uniquely identify a record in a table.
It's used when a single column is not sufficient to ensure uniqueness.
10 DBMS Cheatsheet
Composite Key
A
001 121 P 12 P
003 123 P 10 Q
005 125 P3 R
A candidate key is a set of columns that can An alternate key is a candidate key that is not
uniquely identify a record in a table. From selected as the primary key. It can be used as a
these, one key is chosen as the primary key. unique identifier if needed.
Example:
11 DBMS Cheatsheet
Super Key
Example
1 Tony 24 XXXXXXXX23
2 Wayne 18 XXXXXXXX13
3 Paul 34 XXXXXXXX43
XXXXXXXX23
4 Roy 38 XXXXXXXX66
Did Designation
1 BPO
2 Account
3 IT
12 DBMS Cheatsheet
4 Normalization
4NF 5NF
1NF (First Normal Form) 2NF (Second Normal Form) 3NF (Third Normal Form)
Ensures that each attribute in a Builds on 1NF and ensures that Further refines the normalization
table contains atomic values, non-prime attributes are fully process by ensuring that no
and there is no repeating functionally dependent on transitive dependencies exist.
groups. the primary key.
BCNF (Boyce Codd Normal Form) 4NF (Forth Normal Form) 5NF (Fifth Normal Form)
Ensures that there is no non- Extends normalization by Handles cases where certain
trivial functional dependencies addressing multi-valued join dependencies exist in
of attributes on the primary key. dependencies. the database.
13 DBMS Cheatsheet
Table with
First Second Third Normal Boyce Codd Forth Fifth
Multi-valued
Normal Form Normal Form Form Normal Form Normal Code Normal Code
attributes
5 Indexing in DBMS
21 Address of Block 3
Chapter n 100
14 DBMS Cheatsheet
Outer Index
Search Key Block Pointer
Types of Indexing
15 DBMS Cheatsheet
Secondary Indexing
In secondary Indexing over the key field, the index is created on the unordered key field of the database file.
It is always a dense index.
Clustered Indexing
In clustered indexing, the index is created on the ordered nonkey field of the database file.
16 DBMS Cheatsheet
Non-clustered Indexing
A non-clustered index just tells us where the data lies, i.e. it gives us a list of virtual pointers or references to the location
where the data is actually stored. Data is not physically stored in the order of the index. Instead, data is present in leaf nodes
17 DBMS Cheatsheet
6 Structured Query Language
SQL is a standard programming language used for managing and manipulating relational
databases. It provides a set of commands for interacting with databases, allowing users to
define, query, update, and manage data efficiently.
DBMS Database
Users
Customers
SELECT..
FROM.. Orders
customer_id order_id
....
1 1001
2 1002
3 1003
Result
Apps
Binary, Varbinary,
Binary Varbinary (max), image
18 DBMS Cheatsheet
SQL (Structured Query Language) commands are instructions that interact with a relational
database management system (RDBMS). These commands allow users to perform various
operations such as querying data, updating records, inserting new data, and managing the
structure of a database
SQL Commands
TRUNCATE
SQL Commands
IS NULL/IS NOT NULL EXITSTS Operator Arithmetic Operators LIKE Operator BETWEEN Operator
Operator
+
IS NULL IS NOT NULL - * / % LIKE BETWEEN
19 DBMS Cheatsheet
CRUD stands for create, read, update and delete which represent the fundamental
operations performed on data in a database.
Create Delete
CRUD
new item
Create (INSERT) Read (SELECT)
Used to add new Used to retrive data
records in the table. from one or more new item
tables
new item
Update Delete
new item
Used to modify existing Used to remove records
records in a table. from a table based on
a condition. Read Update
peter@abc.com
suzi@abc.com
joseph@abc.com
alex@abc.com
mark@abc.com
stephen@abc.com
UPDATE Example
mike@abc.com
james@abc.com
robin@abc.com
stephen@abc.com
michael@abc.com
20 DBMS Cheatsheet
Create (INSERT) Example
DELETE Example
21 DBMS Cheatsheet
SQL Clauses are components of SQL statements that defines specific conditions or
actions.
HAVING GROUP BY
GROUP BY Clause INTO Clause
Filter the aggregated Aggregates the base
data data
SELECT ORDER BY
CASE COALESCE
Mathematical Functions Performs conditional Returns the first non-
logic within a query. null value in a list.
22 DBMS Cheatsheet
CASE FUNCTION IN SQL
RESULT TRUE
Mathematical Functions
Rounds a numeric value to Rounds a numeric value up to Rounds a numeric value down
a specified number of the nearest integer. to the nearest integer
decimal places.
23 DBMS Cheatsheet
ROUND Function in SQL
Number of Decimal
SQL ROUND ()
place round to
Output of ROUND ()
Numerical Value to be Rounded
SQL CEILING()
Numerical Value Output of CEILING ()
to be Rounded
SQL FLOOR()
Numerical Value Output of FLOOR ()
to be Rounded
24 DBMS Cheatsheet
Aggregate Functions
MAX
31
25 DBMS Cheatsheet
MIN Function in SQL
MIN(age)
22
COUNT(DISTINCT Country)
3
26 DBMS Cheatsheet
AVG Function SQL
average_age
25.6
total_sales
133509
27 DBMS Cheatsheet
String Function in SQL are used to manipulate and perform operations on character data,
typically text values.
String Functions
UPPER CONCAT
LENGTH LOWER
Syntax : Syntax :
UPPER (str) LOWER (str)
Example : Example :
UPPER (ʻtestʼ) LOWER (ʻTESTʼ)
test TEST TEST test
UPPER () LOWER ()
Syntax : Syntax :
CONCAT (string1, string2, string 3, ...) LENGTH (str)
Example : Example :
concat (” May be A-Z ”, “ or ”, “ may be 0-9 ”) LENGTH (ʻTESTʼ)
TEST 4
Output LENGTH ()
May be A-Z or may be 0-9
passing through function
28 DBMS Cheatsheet
Date functions in SQL are used to perform operations on date and time data types. These
functions help in manipulating, extracting, and formatting date values.
Date Functions
29 DBMS Cheatsheet
DATEDIFF FUNCTION IN SQL
Example :
DATEDIFF('2008-05-17 11:31:31', '2008-04-28')
2008-05-15 22:23:00
'%W %D %M %Y'
DATEDIFF( )
year month day
2008 05 17
(minus) - 2008 04 28
Joins in SQL
SOL JOIN is used to combine rows from two or more tables based on a related column
between them.
30 DBMS Cheatsheet
INNER JOIN
Table1 Table2
OUTER JOIN
31 DBMS Cheatsheet
LEFT JOIN
Employees
EmployeelD EmployeeName GenderID
SELECT EmployeeID, EmployeeName, Gender
1 Mark 1
FROM Employees LEFT JOIN Genders
2 Sara 2
ON Employees. GenderID = Genders. GenderID
3 Tom NULL
Query Result
Genders
GenderID Gender EmployeelD EmployeeName Gender
1 Male 1 Mark Male
2 Female 2 Sara Female
3 Not Specified 3 Tom NULL
RIGHT JOIN
Employees
EmployeelD EmployeeName GenderID
SELECT EmployeeID, EmployeeName, Gender
1 Mark 1
FROM Employees RIGHT JOIN Genders
2 Sara 2
ON Employees. GenderID = Genders. GenderID
3 Tom NULL
Query Result
Genders
GenderID Gender EmployeelD EmployeeName Gender
1 Male 1 Mark Male
2 Female 2 Sara Female
3 Not Specified NULL NULL NULL
SQL Set Operations are used to combine the results of two or more SELECT queries into a
single result set. The common set operations include UNION, INTERSECT, and
EXCEPT/MINUS (depending on the SQL variant).
32 DBMS Cheatsheet
UNION INTERSECT
MINUS
33 DBMS Cheatsheet
INTERSECT EXAMPLE
1 1
2 2
2 2 1 4
3 3
3 3
A B A INTERSECTS B RESULT
MINUS EXAMPLE
1 1
2
2 2 1 4 1
3
3 3
A B A MINUS B RESULT
34 DBMS Cheatsheet
SQL QUERY PROCESSING
SQL Query Processing involves parsing, optimizing, and executing SQL queries to retrieve
data from databases.
Scanner:
Database Query In the SOL Query Processing, the scanner step
involves tokenizing the SQL query, breaking it into
individual units (tokens) such as keywords, identifiers,
Scanner
literals, and symbols, to facilitate further parsing and
analysis.
Parser
Parser:
The SQL query is analyzed to ensure its syntax is
Validation correct. The query is broken down into components
such as keywords, table names, columns, and
conditions.
Query Optimizer
Validation:
During the validation step in SQL Query Processing, the
Code Generator
database management system ensures the correctness
and integrity of the SQL query by verifying the existence
Result of the Query of referenced tables and columns, checking data types,
and validating syntax and semantics.
selects the most efficient one based on factors like code, determining how to access and manipulate data
indexing, join strategies & available resources in the underlying database system for efficient query
execution.
Database Processor:
Executes the generated code, interacting with the underlying database to retrieve, manipulate, or store data according
to the user's query.
35 DBMS Cheatsheet
7 Transaction Management
A transaction is a sequence of one or more operations (SQL statements) that are executed as a
single, indivisible unit of work. Transaction management in DBMS refers to the process of
ensuring the reliable and consistent execution of database transactions.
ACID Properties
A C I D
Each transaction is The database must be If any statement in the Transaction must
either properly carried in a consistent state transaction fails, the meet all protocols
out or the database before and after the entire transaction defined by the
reverts back to the transaction. fails, and the database ssystem -- no partially
state before the is left unchanged. completed transac-
transaction started. tions.
36 DBMS Cheatsheet
Atomicity
A B
Before $30 Before $100
Transfer Process
Debit $10 Debit $10
A B
Before $30 Before $100
Transfer Process
Debit $10 Debit $10
Consistency
A
Before $300
Debit to B $50
Available $250
Debit to C $20
Data Constistent
37 DBMS Cheatsheet
Isolation
A B
Before $100 Before $50
Debit to B $20
T1
Credit by A $20
Debit to C $20
T1 was $100
Available $60
Value read by Value read by B before
C before T2
was $80 T2
C
Before $70
Credit by A $20
Available $90
Durability
Changes to
Crash
be applied
Reboot
Transaction Log
38 DBMS Cheatsheet
Concurrency Control
It uses locks to restrict access to data, ensuring It allows multiple versions of a data item to
only one transaction can modify a piece of data coexist, enabling transactions to read a snapshot
at a time, preventing conflicts. of the database without blocking each other.
Authentication Log in
Login Name
Users Password
Authorization
Gives users permission to access a resource
Authorization
Permissions
Database
39 DBMS Cheatsheet
DATA BACKUP
Copy Emergency
40 DBMS Cheatsheet
Backup Strategies
Full backup
Backup Repository
Source Data 1st backup 2nd backup 3rd backup 4th backup
41 DBMS Cheatsheet
Incremental Backup
Data is copied in its entirety to begin with, and then only new or updated data is backed up
each time a backup is initiated after that.
Backup Repository
Source Data 1st backup 2nd backup 3rd backup 4th backup
Differential Backup
Data is copied in its entirety to begin with, and then only sets of backup with a change are
backed up each time a backup is initiated after that.
Backup Repository
Source Data 1st backup 2nd backup 3rd backup 4th backup
42 DBMS Cheatsheet
Data Recovery
Data Recovery
43 DBMS Cheatsheet