DBMS
DBMS Part-1
- DBMS Introduction
- DBMS Architecture
- Database Approach vs Traditional File System
- Advantages of DBMS
- Data Models in DBMS
- Schemas in DBMS
- Instances in DBMS
- Data Independence in DBMS
- Database Languages in DBMS
- Interfaces in DBMS
- Structure of DBMS
- Functions of DBA and Designer
- Entities and Attributes in DBMS
- ER Diagram in DBMS
- Generalization, Specialization and Aggregation in DBMS
- Converting ER Diagram to Tables in DBMS
- Difference between Object Oriented, Network and Relational Data Models
DBMS Part-2
- Relational Data Model in DBMS
- Keys in DBMS
- SQL Introduction
- DDL(Data Definition Language)
- DML(Data Manipulation Language)
- Integrity Constraints in DBMS
- Complex SQL Queries
- Joins in DBMS
- Indexing in DBMS
- Triggers in DBMS
- Assertions in DBMS
- Relational Algebra in DBMS
- Tuple Relational Calculus in DBMS
- Domain Relational Calculus in DBMS
DBMS Part-3
- Introduction to Normalization in DBMS
- Normal Forms in DBMS
- Functional Dependency in DBMS
- Decomposition in DBMS
- Dependency Preserving Decomposition in DBMS
- Lossless Join Decomposition in DBMS
- Problems with Null Values and Dangling Tuples
- Multivalued Dependency in DBMS
- Query Optimization in DBMS
- Algorithms for Select, Project and Join Operations in DBMS
- Query Optimization Methods in DBMS
DBMS Part-4
- Transactions in DBMS
- Serializability in DBMS
- Recoverability in DBMS
- Recovery Techniques in DBMS
- Log Based Recovery in DBMS
- Checkpoint in DBMS
- Deadlock in DBMS
- Concurrency Control in DBMS
- Lock Based Protocol in DBMS
- Timestamp Based Protocol in DBMS
- Validation Based Protocol in DBMS
- Multiple Granularity in DBMS
- Multi-Version Concurrency Control(MVCC) in DBMS
- Recovery with Concurrent Transactions in DBMS
DBMS Part-5
Triggers in DBMS
Trigger ek automatic SQL command hota hai jo tab run hota hai jab koi specific event (INSERT, UPDATE, DELETE) kisi table par perform kiya jata hai.
Trigger tab chalta hai jab:
Table me naya record insert hota hai
Table ka data update hota hai
Table se data delete hota hai
Triggers kyu use karte hain?
Triggers ka use hum:
-> Rules ya logic automatically apply karne ke liye karte hain
-> Data ko safe aur consistent rakhne ke liye karte hain
-> Changes ka record rakhne ke liye karte hain (logging)
-> Dusre tables ko auto update karne ke liye karte hain
Trigger kaise kaam karta hai?
Types of Triggers:
1. BEFORE Trigger
Ye trigger tab chalta hai jab actual operation se pehle kuch karna ho.
Jaise ki data check karna ya validate karna.
2. AFTER Trigger
Ye trigger tab chalta hai jab operation ho chuka ho.
Jaise ki changes ko kisi log table me record karna.
3. INSTEAD OF Trigger
Ye mainly views me use hota hai.
Ye normal operation ki jagah kuch aur kaam karta hai.
SQL Example: Salary Update ka Trigger
Maan lo humare paas 2 tables hain:
Table 1: Employees
CREATE TABLE Employees (
EmpID INT PRIMARY KEY,
Name VARCHAR(50),
Salary INT
);
Table 2: Audit_Log
CREATE TABLE Audit_Log (
LogID INT PRIMARY KEY AUTO_INCREMENT,
EmpID INT,
OldSalary INT,
NewSalary INT,
ModifiedDate DATETIME
);
Trigger banate hain jo salary update hone par Audit_Log me entry kare:
CREATE TRIGGER AfterSalaryUpdate
AFTER UPDATE ON Employees
FOR EACH ROW
BEGIN
INSERT INTO Audit_Log(EmpID, OldSalary, NewSalary, ModifiedDate)
VALUES (OLD.EmpID, OLD.Salary, NEW.Salary, NOW());
END;
Iska matlab:
Jab bhi kisi employee ki salary update hogi:
OLD salary record ki jayegi
NEW salary record ki jayegi
Audit_Log table me yeh sab auto store ho jayega
Triggers ke Fayde (Advantages)
Automation: Repeated kaam auto ho jata hai
Consistency: Har baar same rule follow hota hai
Security: Galat data se bachav
Logging: Changes ka record automatically banta hai
Triggers ke Nuksaan (Disadvantages)
Hidden logic: Kabhi-kabhi samajhna mushkil hota hai ki kya kaam trigger se ho raha hai
Debugging tough: Problem find karna thoda tricky hota hai
Performance: Agar zyada triggers ho gaye to database slow ho sakta hai
Summary Table:
Feature | Explanation |
---|---|
Trigger kya hai? | Auto SQL code jo event pe chalta hai |
Trigger kab chalta hai? | INSERT, UPDATE, DELETE ke time |
Types of Triggers | BEFORE, AFTER, INSTEAD OF |
Use kisliye hota hai? | Logging, Validation, Auto Updates |