Dbms Short Notes Compressed
Dbms Short Notes Compressed
GATE फर्रे
Tuple : A tuple is a single row in a relation (table), Armstrong’s Axioms (or inference rules) provide a
representing a single record in that table. sound and complete set of rules for reasoning about
functional dependencies (FDs) in relational database
Attribute : An attribute refers to a column in a relation. design.
It defines the properties or characteristics of the
relation. Let X, Y, Z, W be sets of attributes. The following three
fundamental axioms form the basis of all functional
Domain : The domain of an attribute is the set of all dependency inference:
possible values that an attribute can take. It defines the
data type and constraints of the attribute. Rule Name Rule
Degree : The degree of a relation is the total number of Reflexivity If X⊇YX, then X→Y
Cardinality : The cardinality of a relation is the total Transitivity If X→Y and Y→Z, then X→Z
number of tuples (rows) present in it. Decomposition If X→YZ, then X→Y and X→Z
Relational Instance : A relation instance is a specific set Union If X→Y, and X→Z, then X→YZ
Page No:- 01
DBMS
GATE फर्रे
Key Concept Finding Multiple candidate Key : First find any one
candidate key in relation R, the attribute present in
Primary key: Randomly chosen candidate key is the that candidate jey is key/prime attribute.
primary key which is Unique and Not Null.
If X → {Prime/Key Attribute}, then multiple
Attribute
Alternate Key: All other keys are alternate keys from candidate keys are possible.
the set of candidate keys, except the primary key.
Relation F⊃G G⊃F F=G Uncomaparabl
e
Super-key: If all attributes of relation R is determind
by attribute (attribute set) closure of X [X]+ . The F Covers G True False True False
Example: consider Emp-id as a candidate key in a Minimal cover: To eliminate redundant FD.
relation Employee.
Then, {Emp-id, Emp-name} is a super-key. Minimal / Canonical cover: Sets of FD may have
redundant dependencies that can be inferred from
Candidate key: The minimal superkey is defined as others.
the candidate key.
R(ABCDE) [AB → C, C → D, B → EA] Procedure to find canonical cover:
[AB]+ = [ABCDE], therefore AB is super key, 1. Split the FD such that RHS contain single attribute
[A]+ = [A] Ex. A → BC : A → B, A → C
[B]+ = [ABCDE], therefore B is the candidate key. 2. Find the redundant attribute on LHS and delete
them.
Key / Prime attribute: Set of attributes which belongs 3. Find the redundant FD and delete them from the
in any candidate key. FD set. { A → B, B → C, A → C } : { A → B, B → C }
Non Key / Non Prime attribute: Set of attributes Note: Minimal cover may or may not be unique i.e. we
which does not belong in any candidate key. can have more than one.
Key/prime attribute = [B]
Non key/ Non Prime attribute = [A, C, D, E] Finding number of super key: Let R be the relational
Note: To find the candidate key, first find the super schema with n attributes A1, A2, ….An
key, then check the minimum of that super key. Total number of super keys = 2n-1
Ex. With only CK A1, A2
Membership set Maximum number of candidate key = n C ⌊n/2⌋ , Where n
Let F be a given set of functional dependencies. is number of attributes.
A functional dependency X→Y is said to be a member
of F+ (i.e., logically implied by F) iff
Normalization
X→Y ∈ F+ ⟺ Y ⊆ X+
Where X+ is the attribute closure of X with respect to
Why Normalisation?
the set F.
To eliminate the following anomalies.
Equality between 2FD set: Insertion Anomalies
Let two FD set F & G give Updation Anomalies
Deletion Anomalies
Properties of Decomposition
Page No:- 02
DBMS
GATE फर्रे
Page No:- 03
DBMS
GATE फर्रे
Note:
2NF 3NF Checking BCNF Checking
Checking
Page No:- 04
DBMS
GATE फर्रे
Module: 2 ER Model
Page No:- 01
DBMS
GATE फर्रे
Page No:- 06
DBMS
GATE फर्रे
SQL
SELECT DISTINCT A1, A2, …… An
FROM R1, R2, …… Rn
WHERE condition
GROUP BY (attributes)
HAVING condition
ORDER BY (attributes) (DESC)
DDL (Data Definition Language): Used to define or Execution Flow
modify the structure of database schema objects FROM cross-product of relations
(like tables, views, indexes). WHERE Selection operator () to apply condition for
CREATE: Creates a new table, view, or other each record
object. GROUP BY
ALTER: Modifies an existing object (e.g., add a HAVING
column). SELECT
DROP: Deletes an existing object. DISTINCT ORDER BY
TRUNCATE: Removes all rows from a table
quickly (no rollback). GROUP BY:
• It is used to group records data based on specific
DML (Data Manipulation Language): Used to attributes.
manipulate data in existing tables. • It GROUP BY clause used then
SELECT: Retrieves data from one or more (a) Every attribute of the GROUP BY clause must be
tables. selected in SELECT clause.
Page No:- 07
DBMS
GATE फर्रे
(b) Not allowed to select any other attribute in the 6. Default: Specifies a default value when none is
SELECT clause. provided during insert
Allowed to select aggregate function along with
GROUP BY attribute in SELECT Clause. ALTER TABLE Statement
The ALTER TABLE command is used to modify the
HAVING Clause structure of an existing table.
• HAVING clause must be followed by GROUP BY Add a new column
clause. Drop (delete) a column
• HAVING clause used to select groups that are Modify column data type, rename columns, rename
satisfied having clause condition. table (DBMS-specific)
• HAVING clause condition must be over aggregation Aggregate Functions: Aggregate functions perform
function such as some ( ), Every ( ) etc. but not allowed calculations over a set of rows and return a single
direct attribute summary value.
comparison 1. Avg() - Mean value of numeric column
2. Count() - Returns the number of rows that
Note: Every Query which is written by using match a condition.
HAVING clause can be re-written by using WHERE 3. Sum() - Returns the total values
clause. 4. Min() - Returns the smallest value
5. Max() - Returns the largest value
Nested Query Without Co-relations: Inner query
independent of outer query. Nested Query Without Co-relations: It is
independent of the outer query.
SQL Constraints Inner Query → Runs independently and
Key Properties: returns a result.
Constraints can be defined: Outer Query → Uses the inner result to
During table creation (CREATE TABLE) complete execution.
After table creation using ALTER Example:
TABLE SELECT name
If any data violates a constraint, the database FROM employees
system rejects the operation (insert/update). WHERE dept_id IN (
1. Not Null: Ensures that a column must always SELECT id
hold a value FROM departments
2. Unique: Ensures all values are distinct in the WHERE location = “Delhi”
column or column set );
3. Primary Key: Combines NOT NULL + UNIQUE Co-related Nested Query
Uniquely identifies each record. Can consist of In Nested Co-related query inner query uses attributes
one or more columns (composite key). Each from outer query tables.
table can have only one PRIMARY KEY In Co-related Nested query inner query allowed in
4. Foreign Key: Maintains referential integrity WHERE, HAVING clause of outer query.
Enforces a relationship between columns in Example: SELECT A
two tables FROM R
The referencing column(s) must match values WHERE (SELECT count(*)
in the referenced table's PRIMARY or UNIQUE FROM S
key. Can be NULL if not marked NOT NULL WHERE S.B < R.A) < 5;
5. Check :Restricts the range or condition of NOTE: If co-relation in WHERE clause then inner query
values in a column re-computes for each record of outer query From
Page No:- 08
DBMS
GATE फर्रे
Page No:- 09
DBMS
GATE फर्रे
If the number of levels = k, and we also access the Non - Root ( BP) ⌈P/2⌉ P
data block, Total block accesses = k +1
Then total number of block accesses to locate a record Root (Keys) 1 P-1
is k + 1
Non Root (Keys) ⌈P/2⌉ - 1 P-1
Multilevel Index
Order P:
A multilevel index treats the index file itself as an
P * BP + P(Keys + RP) <= Block size.
ordered file (first or base level). A second-level index
(P + 1) BP + P(Keys + RP) <= Block Size
is then created on this first-level index, acting like a
Note: Maximum level: At each level min # key & min #
primary index using block anchors—one entry per
Bp (⌈P/2⌉−1, ⌈P/2⌉)
block of the first level. Since all index entries are of the
Minimum level: At each level maximum # key & max #
same size, the blocking factor remains the same
Bp (P−1, P)
across all levels.
Applicable for both B and B+ Tree
B Tree
B+ Tree
All keys are available at leaf node
Page No:- 01
DBMS
GATE फर्रे
Left biasing ⇒
If x ≤ K₁
If K₁ < x ≤ K₂
Right biasing ⇒
If x < K₁
If K₁ ≤ x < K₂
Page No:- 11
DBMS
GATE फर्रे
Chapter 5: Transaction and Concurrency Control System crash - If System crash/failure happen,
A transaction is a collection of operations that forms a required operation to recover are
single logical unit of work. (I) All committed transactions until the previous
checkpoint will perform Redo.
Operation in Transaction (II) All uncommitted transactions in the entire system
Read (A) - This operation transfers the current value of will perform undo.
data item A from the database (typically stored on disk) (III) Clean all log entries.
into a local variable in the transaction's main memory Roll back - Undo modification of database files which
workspace. It enables the transaction to access and use are done by failure transaction.
the value of A during its execution. Durability - If a transaction completes successfully and
the user is notified, the changes made by the
Write (A) - This operation stores the modified value of transaction must persist, regardless of what happens
data item A from the transaction's local workspace (in next.
main memory) back into the database (on disk), thereby
making the changes made by the transaction visible in Durability Mechanisms
the database.
Write-Ahead Logging (WAL): Log records are
BEGIN TRANSACTION - Marks the starting point of a written before actual data is updated.
transaction. Allocates resources and begins logging.
END TRANSACTION - Marks the logical end of the Redo Logging: During recovery, the system reapplies
transaction. Actual commit or abort happens later. the effects of committed transactions using the log.
Commit - Makes all changes made by the transaction
permanent in the database. Stable Storage: Assumes existence of a reliable
Abort - Undoes all changes made by the transaction storage medium that survives crashes (or is emulated
and restores the database to its previous consistent using replication, RAID, etc.).
state.
Consistency - It ensures all integrity constraints are
Atomicity : Atomicity ensures that a transaction is all- preserved.
or-nothing — either all operations of the transaction
are executed successfully, or none of them are. Isolation - Each transaction should appear to execute
in isolation, even when multiple transactions are
Goal: Prevent partial updates that can lead to data running concurrently.
inconsistency.
Isolation issues - Dirty read, Non-repeatable read,
Maintained by: Recovery subsystem using undo Phantom read.
(rollback) operations.
Schedules - Time order execution sequence of two or
Operation Purpose Affects more transactions.
Page No:- 12
DBMS
GATE फर्रे
W(A)
● A transaction must acquire a lock on a data
item before accessing it.
○ Write–Write
● Locks are automatically released when the
T1 T2
transaction commits or aborts.
W(A)
● Locking protocols are sets of rules that
W(A) govern how locks are acquired and released to
ensure serializability.
View Serializability
● Three checks: ● Improper use of locks may lead to issues like
Initial read deadlocks, starvation, and reduced
Updated read concurrency.
Final write
● Locking restricts non-serializable schedules
● Conflict serializable ⇒ View serializable, but by design.
not vice versa.
Lock Granularity
Why Concurrent Execution? Granularity refers to the size of the data item that
● Increases throughput of the system can be locked. Coarser granularity reduces overhead
● Maximizes resource utilization but limits concurrency, while finer granularity increases
● Reduces waiting time for users overhead but allows higher concurrency.
T1 T2
Database-Level Locking
W(A) ● Locks the entire database.
Page No:- 13
DBMS
GATE फर्रे
● Drawback: Poor concurrency – only one ● Overhead: High, due to managing a large
transaction can access the DB. number of locks.
Page No:- 14
DBMS
GATE फर्रे
Page No:- 01
DBMS
GATE फर्रे
Page No:- 16
DBMS
GATE फर्रे
Reject the write; rollback T (a younger Starvation is possible for younger transactions, as they
transaction has already written X). may be repeatedly rolled back if older transactions
Else: continuously block them.
Allow them to write.
Set WTS(X) = TS(T). 2. Wound Wait Protocol (Non- Preemptive)
Page No:- 17