DBMS Notes by Khyati

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 29

[DBMS NOTES BY KHYATI]

UNIT- 1
Introduction to Database
Database ek aisi systematic collection hoti hai jisme data ko store, organize, aur retrieve kiya
ja sakta hai. Yeh information ko ek structured tarike se manage karta hai, taki users easily access
kar sakein.
Database ke kuch important terms:
1. Data: Database me store hone wala koi bhi information.
2. Database Management System (DBMS): Yeh ek software hai jo database ko create, update,
aur manage karta hai. Examples: MySQL, Oracle, Microsoft SQL Server.
3. Table: Database me data ko organize karne ke liye tables ka use hota hai. Har table ek
specific type ke data ko represent karta hai.
4. Record/Row: Table me har ek entry ko record ya row kehte hain. Yeh ek individual data
point hota hai.
5. Field/Column: Har record me specific information ko represent karne ke liye columns ka
use hota hai. Jaise ki ek student ki details me naam, roll number, aur course.

Database ka use kyun karte hain:


1. Data Organization: Database data ko structured tarike se organize karta hai, jisse
information ko easily manage kiya ja sake.
2. Data Retrieval: Users ko chahiye wala data jaldi aur efficient tarike se mil jata hai.
3. Data Security: DBMS ke through access control aur encryption ka use karke data ko protect
kiya ja sakta hai.
4. Data Integrity: Database assure karta hai ki data sahi aur consistent rahe, taki galat
information ka use na ho.
5. Concurrency Control: Multiple users ke simultaneous access ko manage karke data
consistency ko maintain karta hai.

DATA MODELS
Hierarchical Model
Hierarchical database model ek tree-like structure mein data ko organize karta hai jisme ek root
hota hai, jise sabhi dusre data se link kiya jata hai. Har record database mein ek node ki tarah
hota hai, aur node ke beech mein parent-child links establish hote hain. Is model mein, har
parent ke paas multiple children ho sakte hain, lekin har child ka sirf ek hi parent hota hai. Ye
model intuitive aur samajhne mein aasan hota hai, lekin data badhne par ise manage karna
mushkil ho sakta hai.
[DBMS NOTES BY KHYATI]

Data ek tree jaise structure mein organize hota hai jisme do alag prakar ke data ke beech ek
one-to-many relation hota hai, jaise ki ek department ke paas kai courses, kai teachers, aur
beshak kai students ho sakte hain (jo neeche diagram mein dikhaya gaya hai).

Network Model
Network database model hierarchical model ka extension hai aur ismein complex relationships
ko represent karne ki sujhav di jati hai. Iska use graph structure mein hota hai jisme nodes
records ko aur edges records ke beech ke relationships ko darust karte hain. Hierarchical model
ke vipreet, network model mein ek child record ko ek se zyada parent ho sakte hain. Ye
flexibility complex relationships ko represent karne mein madad karta hai, isliye ise kuch khas
scenarios mein istemal kiya jata hai.

Relational Model
Relational database model data ko tables mein organize karta hai, jisme har table rows aur
columns se bani hoti hai. Har row ek record ko represent karti hai, aur har column ek record ki
attribute ko. Tables ek dusre se common fields ke through relate ho sakte hain, jisse alag-alag
sets ke data ke beech mein ek logic connection ban jata hai. Ye model mathematical set theory
par adharit hai aur aajkal ke database management systems (DBMS) mein widespread istemal
hota hai. Relational model ek sidha aur flexible tareeke se data ko manage karne ka ek popular
tareeka hai.
[DBMS NOTES BY KHYATI]

Feature Hierarchical Model Network Model Relational Model


Structure Tree-like structure Graph structure Tables with rows and
columns
Relationships One-to-many Many-to-many Relationships defined
relationships within a relationships in a by common fields
tree graph
Flexibility Limited flexibility due More flexibility due High flexibility,
to strict hierarchy to multiple supports complex
relationships relationships
Complexity Simple for certain Handles complex Handles complex
Handling relationships, can relationships well relationships well, easy
become complex to understand
Parent-Child Each child has one A child can have No explicit parent-child
Links parent multiple parents links, relationships
through keys
Example File system structure Organizational charts Database tables with
related data

Database System architecture


• DBMS ka design uske architecture par depend karta hai. Basic client/server architecture
ka istemal ek bade number mein PCs, web servers, database servers, aur doosre
components ko handle karne ke liye hota hai jo ek network se judhe hote hain.
• Client/server architecture mein kai PCs aur ek workstation network ke zariye connect
hote hain.
• DBMS ka architecture yeh batata hai ki users database se kaise judte hain aur apne
requests ko kaise complete karte hain. Isme, ek workstation ya server hota hai jo database
ko control karta hai, aur saath hi kai PCs hote hain jo users ke requests ko bhejte hain aur
database se data retrieve karte hain.
• Is architecture mein, har ek user apne local PC ya workstation se database server se
connect karta hai, jo ki ek central location par hota hai. Yeh design scalability aur
efficiency ko bhi dhyan mein rakhta hai, khaaskar jab bahut saare users ek sath database
se interact karte hain.

Types of DBMS Architecture


DBMS architectures can be categorized into one-level, two-level, and three-level architectures
based on the number of levels of abstraction or layers.
[DBMS NOTES BY KHYATI]

One-Level Architecture:
o Isko "Single-tier" architecture bhi kehte hain.
o Issme ek hi interface ya layer hoti hai jisme DBMS aur application tightly connect hote
hain.
o Application seedhe data management system se interact karta hai.
Characteristics:
o Sabse simple architecture.
o Abstraction aur concerns ko limit mein rakhta hai.
o Application mein ki gayi changes seedhe data management ko affect kar sakti hain.
Use Cases:
o Small-scale applications jahan complexity kam hoti hai.

Database User

Two-Level Architecture:

o Isko "Client-Server" architecture bhi kehte hain.


o User interface aur database management system ke beech ek aur layer introduce hoti
hai.
o Application database se communication ek middle layer ke through hoti hai.
Layers:
o User Interface (Front-end): User se interact karta hai aur user ke requests ko process
karta hai.
o DBMS (Back-end): Data storage, retrieval, aur processing ko manage karta hai.
[DBMS NOTES BY KHYATI]

Characteristics:
o Improved modularity aur concerns ka better separation.
o Application mein ki gayi changes seedhe DBMS ko affect nahi karti.
o Concurrent user access ko allow karta hai.
Use Cases:
o Medium se lekar large-scale applications jahan complexity badh jaati hai.

Three-Level Architecture:
o Isko "Three-tier" architecture bhi kehte hain.
o User interface aur database management system ke beech ek middleware ya application
server layer add hoti hai.
o Scalability, flexibility, aur maintainability ko enhance karta hai.
Layers:
o User Interface (Presentation): User interaction aur input ko handle karta hai.
o Application Server (Logic): Business logic, processing, aur application-specific
functions ko manage karta hai.
o Database Server (Data): Data storage, retrieval, aur management ko handle karta hai.

Characteristics:
o Concerns aur abstraction mein maximum separation.
o Distributed computing aur scalability ko facilitate karta hai.
o Ek layer mein ki gayi changes doosre layers ko directly affect nahi karti.
Use Cases:
o Large-scale applications jinme complex business logic, distributed users, aur data ho.
[DBMS NOTES BY KHYATI]

Data Abstraction
Data Abstraction ek concept hai jiska istemal programming aur software engineering mein hota
hai. Iska mukhya uddeshya complex systems ko simplify karke, aur users ya developers ke liye
asaan aur samajhne mein madad karna hai. Data Abstraction ek tarah se information hide karke,
sirf zaroori aur relevant details ko dikhane ka kaam karti hai.
Yeh do prakar ki hoti hai:
1. Logical Data Abstraction:
• High-Level View: Users ko system ke internal details se mukt rakhti hai. Jaise ki, ek
database system mein, logical data abstraction table, relationship, aur query ke level par
kaam karega, bina yeh dikhaye ki data physical storage kaise hota hai.
• Simplicity: Users ko sirf un details ko dikhaya jata hai jo unke specific kaam ke liye
zaroori hain, baaki internal complexity chhupi rehti hai.
• Example: Relational Database Management System (RDBMS) logical abstraction
provide karta hai jismein data tables aur relationships ke roop mein dikhaya jata hai,
bina actual storage details dikhaiye.
2. Physical Data Abstraction:
• Low-Level View: Developers ya system architects ke liye hoti hai, jo system ke internal
working aur optimization ke liye important hoti hai.
• Implementation Details: Yeh dikhati hai ki data kaise store hota hai, kis tarah ke
indexing ka istemal hota hai, aur data retrieval kaise hoti hai.
• Example: Ek database system mein, physical data abstraction actual disk storage, file
structures, indexing techniques, etc. ke details provide karta hai.
Importance of Data Abstraction
• Complexity Management: Bade aur complex systems ko manageable pieces mein
divide karke samjhne mein madad karta hai.
• Security: Logical abstraction data ko secure rakhta hai kyun ki users sirf unki specified
access level tak hi pahunch sakte hain.
• Ease of Use: Users ko unnecessary technical complexities se bachata hai, aur sirf unki
specific kaam ke liye relevant information dikhata hai.
• Maintenance: System ko upgrade ya modify karne mein madad karta hai bina overall
functionality ko affect kiye.
Example:
Consider a car as an example of data abstraction. A driver interacts with the car using a simple
interface like the steering wheel, pedals, and dashboard. The driver doesn't need to know the
complex internal workings of the engine, transmission, or electronics. This simplified interface
is a form of data abstraction that allows the driver to use the car without being overwhelmed
by the details of how it operates under the hood.
[DBMS NOTES BY KHYATI]

Data Independence
Data Independence ek concept hai jo database systems mein hota hai aur yeh batata hai ki hum
kaise taur par data ko store aur access karte hain, woh change ho sakta hai bina kisi external
application ya user ko affect kiye.
Yeh do tarikon mein hota h
1. Physical Data Independence:
o Physical Data Independence ka matlab hai ki hum internal schema mein kuch bhi
badlav karein bina conceptual schema ko alter kiye, aur database ka structure same
dikhna chahiye.

o Maan lo, agar hum database system server ke storage size mein koi changes karte hain,
toh hume yeh ensure karna chahiye ki jo conceptual structure hai, woh bina kisi user
interface ya conceptual schema ke change ke, waisa hi dikhe.

o Iska use hota hai conceptual level ko internal levels se separate rakhne ke liye.

o Yeh changes internal level par hote hain, jaise storage size, performance optimization,
lekin user ko yeh changes nahi dikhe. Yeh changes logical interface level par hoti hain.

2. Logical Data independence


o Logical Data Independence ka matlab hai ki hum conceptual schema mein koi bhi
changes karein bina external schema ko modify kiye, aur user ko yeh dikhe ki kuch
badla hai ya nahi.

o Jaise ki agar humare paas ek database hai aur hum uske conceptual view mein kuch
badlav karte hain, for example, kisi table ka structure modify karte hain, toh user jise
data dekh raha hai, usko kuch farak nahi padna chahiye. Uska view waisa hi rehna
chahiye jaise pehle tha.

o Iske use se hum external level ko conceptual view se alag rakh sakte hain.

o Agar hum user interface mein kuch changes karte hain, toh bhi user ko pata nahi chalna
chahiye ki actual database ke structure mein kuch badla hua hai. Yeh changes user
interface level par hoti hain.
[DBMS NOTES BY KHYATI]

Data Definition Language (DDL)

Data Definition Language (DDL) ek category hai SQL (Structured Query Language) mein,
jiska istemal database structure ko define aur modify karne ke liye hota hai. DDL commands
databases ke schema (structure) ko control karte hain.

Kuch important DDL commands hain:

1. CREATE:
• CREATE TABLE: New table create karta hai.
• CREATE DATABASE: Naya database create karta hai.
Ex.
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
2. ALTER:
• ALTER TABLE: Existing table ko modify karta hai.
Ex.
ALTER TABLE Students
ADD COLUMN Grade CHAR(1);
3. DROP:
• DROP TABLE: Table ko delete karta hai.
• DROP DATABASE: Database ko delete karta hai.
Ex.
DROP TABLE Students;

Data Manipulation Language (DML):

Data Manipulation Language (DML) commands database mein data ko retrieve, insert, update,
aur delete karne ke liye istemal hote hain. DML commands database ke records ke saath kaam
karte hain.
Kuch important DML commands hain:

1. SELECT:
• SELECT: Data retrieve karne ke liye istemal hota hai.

Ex.
SELECT * FROM Students;
2. INSERT:
• INSERT INTO: Naye data ko table mein insert karne ke liye istemal hota
hai.
Ex.
INSERT INTO Students (StudentID, Name, Age) VALUES (1, 'Kundan', 20);
[DBMS NOTES BY KHYATI]

3. UPDATE:
• UPDATE: Existing data ko modify karne ke liye istemal hota hai.
Ex.
UPDATE Students SET Age = 21 WHERE StudentID = 1;

4. DELETE:
• DELETE FROM: Data ko delete karne ke liye istemal hota hai.
Ex.
DELETE FROM Students WHERE StudentID = 1;

Data models
Data models are abstract representations of the structure of a database and the relationships
between its elements. They provide a way to organize and understand the data within a
database. There are several types of data models, each serving different purposes.
Here are three common types:

Data Models

Entity Object- Document


Hierarchical Network Data Relational
Relationship Oriented Data Oriented Data
Data Model Model Data Model
Model Model Model

1. Hierarchical Data Model:


o Yeh ek tree-like structure mein data ko represent karta hai jisme har node ka ek parent
hota hai aur uske multiple children hote hain.
Example: Organizational charts ya file systems isme include hote hain, jisme har directory ya
node ke subdirectories ya files hote hain.
2. Network Data Model:
o Yeh hierarchical model ko extend karta hai aur har child ko multiple parents dene ki
anumati deta hai.
o Isme records ke beech mein complex relationships ko represent karne ke liye pointers
ka istemal hota hai.
Example: Kuch early database systems mein iska istemal complex relationships ko model
karne ke liye hota tha.
3. Relational Data Model:
o Yeh data ko tables mein rows aur columns ke roop mein represent karta hai.
o Keys ka istemal tables ke beech mein relationships ko establish karne ke liye hota hai.
[DBMS NOTES BY KHYATI]

Example: Tables jisme entities (jaise ki customers, products) ko represent kiya jata hai, aur
keys ke through relationships define kiye jate hain.

4. Entity-Relationship Model:
o Yeh entities aur unke relationships ko graphical taur par represent karta hai.
o Entities objects ya concepts hote hain jinme attributes hote hain, aur relationships define
karte hain ki entities kaise judte hain.
Example: Database design ke initial stages mein entities aur unke interactions ko visualize
karne ke liye use hota hai.
5. Object-Oriented Data Model:
o Yeh data ko objects ke roop mein represent karta hai, jo object-oriented programming
ke tarah hota hai.
o Data aur us par kaam karne wale methods ko encapsulate karta hai.
Example: Applications jahan data aur behavior closely linked hote hain, jaise ki object-
oriented programming languages mein.
6. Document-Oriented Data Model:
o Yeh data ko documents (jaise ki JSON ya XML) ke roop mein represent karta hai jo
nested structures ko contain kar sakte hain.
o Semi-structured data ko store aur query karne ke liye suitable hai.
Example: NoSQL databases mein diverse data types ko handle karne ke liye commonly used
hota hai.
Integrity constraints
Integrity constraints database management system mein data consistency, accuracy, aur
reliability ko maintain karne ke liye use hone wale rules aur restrictions hote hain. Ye
constraints ensure karte hain ki database mein stored data specified rules ke mutabiq ho aur
unwanted ya inconsistent data ko prevent karte hain. Kuch mukhya types ke integrity
constraints hote hain:

1. Primary Key Constraint:


- Har table mein ek column ko primary key declare kiya ja sakta hai. Yeh unique
values hold karta hai aur NULL values ko allow nahi karta.
- Is constraint se table ke har row ko uniquely identify kiya ja sakta hai.
Example:
CREATE TABLE Students (
StudentID INT PRIMARY KEY,
Name VARCHAR(50),
Age INT
);
[DBMS NOTES BY KHYATI]

2. Foreign Key Constraint:


- Foreign key ek table ke column ka reference hota hai jo kisi dusre table ke
primary key se linked hota hai.
- Yeh constraint relationships ko define karta hai, aur data integrity ko maintain
karta hai.
Example:
CREATE TABLE Courses (
CourseID INT PRIMARY KEY,
CourseName VARCHAR(50)
);

CREATE TABLE Enrollments (


EnrollmentID INT PRIMARY KEY,
StudentID INT,
CourseID INT,
FOREIGN KEY (StudentID) REFERENCES Students(StudentID),
FOREIGN KEY (CourseID) REFERENCES Courses(CourseID)
);

3. Unique Constraint:
- Unique constraint ek column ya set of columns ko unique values hone ki
guarantee deta hai. Duplicate values allow nahi hote.
- Yeh constraint data consistency ko maintain karta hai.
Example:
CREATE TABLE Employees (
EmployeeID INT PRIMARY KEY,
FirstName VARCHAR(50),
LastName VARCHAR(50),
UNIQUE (EmployeeID)
);

4. Check Constraint:
- Check constraint ek column mein specific conditions ya expressions ko satisfy
karne ki guarantee deta hai.
- Yeh constraint unwanted data ko prevent karta hai.
Example:
CREATE TABLE Orders (
OrderID INT PRIMARY KEY,
OrderDate DATE,
OrderAmount DECIMAL(10, 2),
CHECK (OrderAmount > 0)
);

5. Not Null Constraint:


- Not Null constraint specify karta hai ki ek column mein NULL values allow
nahi honge.
[DBMS NOTES BY KHYATI]

- Yeh constraint data accuracy ko maintain karta hai.


Example:
CREATE TABLE Customers (
CustomerID INT PRIMARY KEY,
CustomerName VARCHAR(50) NOT NULL,
Email VARCHAR(50)
);

Integrity constraints ek database mein data quality aur consistency ko improve karte hain, aur
database management system in constraints ke through specified rules ko enforce karta hai.
[DBMS NOTES BY KHYATI]

UNIT – 2
Relational query languages
Relational algebra
Relational algebra ek theoretical query language hai jo relational databases ke design aur
manipulation ke liye use hota hai. Ye language mathematical expressions ka use karta hai jo
relations (tables) ke operations ko represent karte hain.

1. Select (σ): Select operation ka use kisi specific condition ke based par rows ko filter karne
ke liye hota hai. Jaise ki SQL mein WHERE clause ka use hota hai.

Example: σ<sub>Salary > 50000</sub>(Employees)


Is expression se humein woh employees milenge jinki salary 50000 se zyada hai.

2. Project (π): Project operation se hum specific columns ko select karte hain. Ismein only
specified columns ko retain kiya jata hai.

Example: π<sub>Name, Age</sub>(Employees)


Is expression se humein Employees table se sirf Name aur Age columns milenge.

3. Union (∪): Union operation se do relations ko combine kiya jata hai aur duplicate entries ko
remove kiya jata hai.

Example: R∪S
Yahaan R aur S ke common columns hone chahiye, aur ye operation un dono relations ko
combine karega.

4. Intersection (∩): Intersection operation se common entries ko retain kiya jata hai, matlab
woh entries jo dono relations mein common hain.

Example: R∩S
Yahaan R aur S ke common columns hone chahiye, aur ye operation un common entries ko
dikhayega.

5. Difference (-): Difference operation se ek relation se doosre relation ke entries ko subtract


kiya jata hai.

Example: R-S
Is expression se R mein se woh entries nikali jaayengi jo S mein exist nahi karte.
[DBMS NOTES BY KHYATI]

Tuple Relational Calculus (TRC):


Tuple Relational Calculus mein hum chaahe woh information janna chahein jo tuples ke
through express hoti hai. Ismein hum woh tuples specify karte hain jinke properties humein
retrieve karni hai.

Example:
Maan lo, ek relation hai R(Name, Age, Salary) aur humein woh employees chahiye jinki salary
50000 se zyada hai. TRC mein, ye express ho sakta hai:

{ t ∣ t∈ R ∧ t[Salary]>50000}
Iska matlab hai "wah set of tuples 't' jisme 't' relation R ka hissa hai aur 't[Salary]' 50000 se
zyada hai."

Domain Relational Calculus (DRC):


Domain Relational Calculus mein hum chaahe woh information janna chahein jo attributes ke
domains ke through express hoti hai. Ismein hum specify karte hain ke attributes ke values kis
range mein hone chahiye taki result set retrieve ho.

Example:
Agar hum wahi relation R(Name, Age, Salary) lete hain aur humein woh employees chahiye
jinki salary 50000 se zyada hai, toh DRC mein ye express ho sakta hai:

{Name∣∃Age,Salary(R(Name,Age,Salary)∧Salary>50000)}
Iska matlab hai "wah set of names jisme kuch aise Age aur Salary exist karte hain jisse R(Name,
Age, Salary) true hota hai aur Salary 50000 se zyada hai."

Domain Dependency
Domain dependency ka matlab hota hai ek relational database mein attributes ke beech ka
relation, jahaan ek attribute ke values doosre attribute ke values par depend karte hain, aur dono
attributes ek hi domain mein hote hain.

Example:
Maan lo, ek relation hai Employee(Name, EmployeeID, Department, Salary). Is relation mein
Department aur Salary ke beech ek domain dependency hoti hai. Kisi employee ki salary uske
department par depend karti hai. Jaise ki "Finance" department ke employees ki salary "IT"
department ke employees ki salary se alag hogi.

Significance:
Domain dependency ko samajhna ek normalized database design ke liye bahut zaroori hai. Ye
database ko efficient tareeke se organize karne mein madad karta hai aur redundancy ko avoid
karne mein help karta hai.
[DBMS NOTES BY KHYATI]

Data Dependency
Data dependency ka matlab hota hai database mein do data sets ke beech ka relation, jahaan ek
data set mein koi changes hone par doosre data set ko bhi asar hota hai.

Types of Data Dependencies

1. Functional Dependency
Ye ek relation hai do attribute sets ke beech mein, jahaan ek attribute ka value doosre attribute
ka value uniquely determine karta hai.

Example: Ek relation Student(Name, RollNumber, Age) mein agar hum assume karein
ki RollNumber uniquely Name ko determine karta hai, toh yahaan functional
dependency hoti hai.

2. Multivalued Dependency
Ye ek relation hai do attribute sets ke beech mein, jahaan ek set of attributes doosre set ko
uniquely determine karta hai, aur ek tisra set hota hai jo pehle do sets ke independent hota hai.

Example: Ek relation Book(Author, Title, Genre) mein agar Author uniquely determine
karta hai Title aur Genre ko, aur Title aur Genre ek-doosre se independent hain, toh
yahaan multivalued dependency hoti hai.

3. Transitive Dependency
Ye ek relation hai jahaan ek attribute doosre attribute ko teesre attribute ke through determine
karta hai.
Example: Ek relation Classroom(Building, RoomNumber, Professor) mein agar
Building RoomNumber ko determine karta hai aur RoomNumber Professor ko
determine karta hai, toh yahaan transitive dependency hoti hai.

Significance:
Data dependency ko samajhna database normalization ke liye bahut zaroori hai. Ye process hoti
hai data ko organize karne ki, jisse redundancy aur dependency se bacha ja sake. Sahi tarah se
data dependency ko identify aur manage karna data integrity ko assure karta hai aur database
ko data modification operations ke dauran anomalies se bachata hai.

Armstrong's axioms
Armstrong's axioms woh kuch niyam hain jo ek relational database mein functional
dependencies ko define karte hain. Ye niyam William W. Armstrong ne propose kiye the aur
database normalization ke theory mein ek important role play karte hain. Yahan Armstrong's
axioms hinglish mein samjha ja raha hai:

1. Reflexivity Axiom:
- Agar Y X ka subset hai, toh X → Y true hai.
- Symbolically, agar X ⊇ Y hai, toh X → Y.
[DBMS NOTES BY KHYATI]

2. Augmentation Axiom:
- Agar X → Y true hai, toh wahi attribute dono sides mein add karne se
dependency preserve hoti hai.
- Symbolically, agar X → Y hai, toh XZ → YZ.

3. Transitivity Axiom:
- Agar X → Y aur Y → Z dono true hain, toh X → Z bhi true hai.
- Symbolically, agar X → Y aur Y → Z hai, toh X → Z.

Ye axioms hamein samajhne mein aur dusre functional dependencies ko derive karne mein
madad karte hain jo ek relational schema mein ho sakti hain. Ye database design ke
normalization process mein badi bhoomika nibhate hain.

Functional Dependencies
Functional dependency ek aisi rishta hai jo do attributes ke beech mein hota hai. Iska aam taur
par use hota hai primary key aur non-key attribute ke beech mein ek table mein.

X → Y
Functional Dependency (FD) mein, left side ko determinant kehte hain, aur right side ko
dependent kehte hain.
For example:
• Hamare paas ek employee table hai jismein kuch attributes hain: Emp_Id, Emp_Name,
aur Emp_Address.
• Yahaan, Emp_Id attribute Emp_Name attribute ko uniquely identify kar sakta hai kyun
ki agar hamein Emp_Id pata hai, toh hum keh sakte hain ki us associated employee ka
naam kya hai.
• Functional dependency ko likhne ka tareeka:
Emp_Id → Emp_Name
• Ham kah sakte hai ki Emp_Name functionally Emp_Id par depent hai.

Types of Functional dependency

Trivial Dependency:
Agar Y X ka subset hai, toh X→Y ko trivial mana jata hai. For example, A→A ek trivial
dependency hai.

Non-Trivial Dependency:
Agar Y X ka subset nahi hai, toh X→Y non-trivial hota hai. Jaise ki, agar X={A,B} aur Y={C},
toh X→Y non-trivial hai.
[DBMS NOTES BY KHYATI]

Normal forms

1. First Normal Form (1NF):


- Definition: Har column mein atomic (indivisible) values hone chahiye. Koi
repeating groups ya arrays nahi hone chahiye.
- Example: Agar table mein ek column hai jisme multiple phone numbers ek hi
cell mein hain (jaise "123-456-7890, 987-654-3210"), toh yeh 1NF ko violate
karta hai.

2. Second Normal Form (2NF):


- Definition: 1NF ko follow karna important hai aur saath mein yeh bhi, ki sabhi
non-key attributes (columns) primary key par fully functionally dependent ho.
Partial dependencies nahi hone chahiye.
- Example: Agar table ka primary key composite hai (jaise (Emp_Id,
Project_Id)), aur koi non-key attribute sirf ek part (jaise Project_Id) par depend
karta hai, toh yeh 2NF ko violate karta hai.

3. Third Normal Form (3NF):


- Definition: 2NF ko follow karna important hai aur saath mein yeh bhi, ki koi
bhi non-key attribute doosre non-key attribute par depend na kare. Transitive
dependencies nahi hone chahiye.
- Example: Agar table mein columns hain (Emp_Id, Emp_Name, Department,
Manager_Name), aur Manager_Name Department par depend karta hai, toh yeh
3NF ko violate karta hai.

4. Boyce-Codd Normal Form (BCNF):


- Definition: BCNF 3NF ko aur bhi strict banata hai. Yeh yeh maangta hai ki har
non-trivial functional dependency ek superkey ho. Har non-trivial functional
dependency ke liye X → Y, X ek superkey hona chahiye.
- Example: Agar table mein columns hain (Emp_Id, Project_Id, Emp_Name),
aur Emp_Name sirf Emp_Id par depend karta hai, toh yeh BCNF ko violate
karta hai.

5. Fourth Normal Form (4NF):


- Definition: 4NF multiple-valued dependencies ke saath deal karta hai. Yeh
ensure karta hai ki koi bhi non-trivial multi-valued dependencies nahi honi
chahiye.
- Example: Agar table mein columns hain (Emp_Id, Project_Id, Skill), aur Skill
Emp_Id aur Project_Id par depend karta hai, toh yeh 4NF ko violate karta hai.

6. Fifth Normal Form (5NF):


- Definition: 5NF mein deal hota hai cases ke saath jahan multiple overlapping
candidate keys hain. Yeh redundancy ko eliminate karta hai.
- Example: Agar table mein overlapping candidate keys hain (jaise (Emp_Id,
Project_Id) aur (Emp_Id, Skill)), toh yeh 5NF ko violate karta hai.
[DBMS NOTES BY KHYATI]
[DBMS NOTES BY KHYATI]

UNIT – 4
Transaction processing
Ek transaction ek program hai jo ek data processing ke logic unit ke roop mein, ek collection
ke database operations ko shamil karke execute hota hai. Transaction mein kiye jaane wale
operations mein database operations jaise insert, delete, update, ya data retrieve shaamil ho
sakte hain. Yeh ek atomic process hai jo ki puri tarah se execute hota hai ya fir bilkul bhi nahi
hota. Agar ek transaction mein sirf data retrieve hota hai aur koi data update nahi hota, toh use
read-only transaction kehte hain.
Transaction processing ek database management system (DBMS) ka mahatva purna hissa hai
jo data ki integrity aur consistency ko ensure karta hai.

For example, a data update operation can be divided into three tasks −
• read_item() − reads data item from storage to main memory.
• modify_item() − change value of item in the main memory.
• write_item() − write the modified value from main memory to storage.

Concurrency control
Concurrency control ek bahut mahatva purna hissa hai multiple users ke environments mein
transaction processing ka. Yeh ensure karta hai ki kai transactions ek sath execute ho sakti hain
bina ACID properties ko tutne ke.

Concurrency control techniques mein shaamil hain:

1. Locking:
Transactions data items par lock hasil karte hain taki doosre transactions us data ko ek sath
access ya modify na kar sake.

2. Isolation Levels:
Alag-alag isolation levels jaise ki Read Uncommitted, Read Committed, Repeatable Read, aur
Serializable, define karte hain ki concurrent transactions ke beech mein dekhai jane wali aur
interaction ka star kya hoga.

3. Transaction Scheduling:
Scheduler transactions ko kis kram mein execute kiya jayega, yeh tay karta hai, consistency
aur isolation ko banaaye rakhne ke liye.
[DBMS NOTES BY KHYATI]

ACID property
ACID properties ek set hai jo transactions ke reliability aur consistency ko database
management system mein ensure karte hain.

1. Atomicity
Ek transaction ko atomic mana jata hai, arthath yeh ek akela, bhinnahin karya unit ke roop mein
vyavhar hota hai. Ya toh transaction ke andar ke saare operations poore hote hain, ya phir koi
bhi nahi hota. Agar koi bhi hissa transaction mein fail hota hai, toh puri transaction ko pehle ke
sthiti mein lauta diya jata hai, data consistency ko banaaye rakhne ke liye.

2. Consistency
Consistency property yeh ensure karta hai ki ek transaction database ko ek consistent sthiti se
doosre consistent sthiti tak le aaye. Transaction ke execution se pehle aur baad mein integrity
constraints ko poora karna zaroori hai.

3. Isolation
Isolation yeh ensure karta hai ki ek transaction ka execution doosre transactions se alag hota
hai. Halki-bhuliye kai transactions ek sath execute ho sakti hain, lekin unke parinam aise hone
chahiye jaise ki ve kisi kramik kram mein execute ho rahe hain. Isolation interference ko rokta
hai.

4. Durability
Durability yeh guarantee karta hai ki ek transaction jab commit ho jati hai, toh uske asar
database parmanant hote hain, system failures ke bawajood bhi. Jo parivartan committed
transaction dwara kiye gaye hain, ve tikte hain aur nahi ghat-te, sthayi data integrity ko ensure
karte hain.

Locking and timestamp based schedulers\


Database management systems mein, jab bahut saare transactions saath mein chal rahe hote
hain, tab humein kuch techniques chahiye jo ensure karein ki data sahi se manage ho, aur
transactions ek dusre se interfere na karein. Locking aur timestamp-based scheduling yeh dono
techniques hain.

Locking:
Locking ek aisi technique hai jisme hum locks ka istemaal karte hain taaki multiple transactions
ek hi samay mein kisi shared resource (jaise database records) ko access na kar sakein.

Locks Ke Types:
1. Shared Locks: Allow karte hain multiple transactions ko resource ko padhne mein,
lekin likhne mein sirf ek ko.
2. Exclusive Locks: Sirf ek hi transaction ko likhne ki permission dete hain, baaki ko
bilkul bhi nahi.
[DBMS NOTES BY KHYATI]

Lock Granularity:
• Coarse-Grained Locks: Pura table ya bada portion lock hota hai. Simple to implement,
lekin concurrency kam ho sakti hai.
• Fine-Grained Locks: Specific data items ko lock karte hain. Concurrency zyada hoti
hai, lekin complexity badh jaati hai.

Locking Protocols:
• Two-Phase Locking (2PL): Transactions locks acquire karte hain do phases mein - ek
growing phase mein aur ek shrinking phase mein. Ek baar lock release ho gaya, toh
naya lock acquire nahi ho sakta.
• Strict Two-Phase Locking (S2PL): Yeh 2PL ka ek variation hai, jisme unlock tab tak
nahi hota jab tak transaction commit point par nahi pahunch jaata.

Timestamp-Based Schedulers:
Timestamp-based concurrency control mein, har transaction ko ek unique timestamp assign
hota hai, jo uski start time ko represent karta hai. Isse transactions ko order mein rakh ke ensure
hota hai ki ve serializable tareeke se execute ho.

Concurrency Control Mechanism:


Har transaction ko ek unique timestamp milta hai, jo uski start time ko reflect karta hai.
Read aur write operations ko timestamps diye jaate hain.
Transactions ko execute karne ki permission unke timestamps ke basis par milti hai.

Concurrency Control Policies:


1. Timestamp Ordering Protocol (TO): Transactions ko execute karne ka order
timestamps ke hisab se hota hai. Conflicts ko resolve karne ke liye timestamps compare
kiye jaate hain.
2. Thomas Write Rule: Issme, ek transaction jo older timestamp ka hai, vo likhne ke liye
allow nahi hota agar koi newer timestamp waala transaction pehle se likh chuka hai.
3. Validation-Based Protocol: Transactions ko commit karne se pehle validate kiya jaata
hai. Agar conflicts milte hain toh consistency maintain karne ke liye appropriate actions
liye jaate hain.

Database recovery
Database recovery ek critical aspect hai Database Management Systems (DBMS) mein, jo
catastrophic failures ya system crashes ke baad database ko restore karne ka process handle
karta hai. Iska main goal hai data consistency aur durability ko maintain karna, taki kisi bhi
data loss situation mein bhi database recover ho sake.
Database recovery do main components par based hota hai: logging aur checkpointing.
1. Logging:
2. Checkpointing:
[DBMS NOTES BY KHYATI]

Database Recovery Process:

Commit Analysis
Phase Phase

Undo Redo
Phase Phase

• Analysis Phase:
1. DBMS, last checkpoint se lekar crash tak ke logs ko analyze karta hai.
2. Transaction logs se recoverable transactions ko identify karta hai.
• Redo Phase:
1. Identified transactions ke actions ko redo karta hai from the log records.
2. Yeh ensure karta hai ki sabhi transactions ke effects dubara se database mein
apply ho jaayein, takki last consistent state restore ho sake.
• Undo Phase:
1. Jo transactions partially commit hokar crash huye the, unke actions ko undo
karta hai.
2. Is phase mein, incomplete transactions ke effects ko reverse karte huye database
ko last consistent state tak laaya jata hai.
• Commit Phase:
1. Finally, recovery process ke end mein, DBMS sabhi transactions ko commit
mark karta hai, jisse woh officially database mein reflect ho jaayein.
[DBMS NOTES BY KHYATI]

UNIT – 5
Database Security
• Authentication
Authentication ek process hai jisme user ko verify kiya jata hai, yani ki ye confirm kiya jata
hai ki user jo hai woh actual me wahi hai jo woh keh raha hai.

DBMS Me Kaise Kaam Karta Hai - Jab ek user DBMS mein login karta hai, toh
authentication check hoti hai. Yeh username-password pair ya phir koi aur authentication
method ka use karke verify ki jati hai ki user authorized hai ya nahi.

• Authorization
Authorization ek process hai jisme decide kiya jata hai ki ek authenticated user ko kis level ki
permissions aur rights milegi.

DBMS Me Kaise Kaam Karta Hai - Jab user authenticate ho jata hai, toh DBMS decide karta
hai ki user ko kya access aur kya operations perform karne ki permissions di jayengi. For
example, kuch users sirf read access ke liye authorize hote hain, jabki kuch ko write ya delete
operations ke liye bhi authorization milti hai.

• Access Control
Access control ka mtlb hota hai control karna ki kaun kis resource tak pahunch sakta hai aur
kya operations perform kar sakta hai.

DBMS Me Kaise Kaam Karta Hai - Access control policies define ki jati hain jo decide karte
hain ki kaun kis data ko access kar sakta hai aur kya modifications kar sakta hai. Isme role-
based access control bhi include hota hai, jisme roles assign kiye jaate hain aur un roles ke
basis par hi access control decisions li jati hain.

DAC (Discretionary Access Control) Model

DAC model mein, access control decisions users ke discretion (manoranjak) par depend karte
hain. Iska mtlb hai ki data owner ko control hota hai ki kaun kis data ko access karega aur kya
operations perform karega.

DBMS Me Kaise Kaam Karta Hai- Har user ko ek set of permissions di jati hai, aur data
owner decide karta hai ki un permissions ke basis par kaun kis data ko access karega. For
example, ek user ko sirf read access ho sakti hai, jabki doosre ko write ya delete access bhi ho
sakti hai.

MAC (Mandatory Access Control) Model


MAC model mein, access control decisions predefined security policies par depend karte hain.
Yeh policies typically government ya organization ke dwara set kiye jaate hain aur har user ko
un policies ke according access milti hai.
[DBMS NOTES BY KHYATI]

DBMS Me Kaise Kaam Karta Hai - Har user ko ek security label diya jata hai, aur data
objects bhi in labels ke sath tag kiye jaate hain. Access tabhi allowed hota hai jab user ka label
data object ke label se match karta hai. Isme data owner ka discretion nahi hota, balki
predefined rules follow hote hain.

RBAC (Role-Based Access Control) Model


RBAC model mein, access control roles ke basis par defined hote hain. Har user ko ek ya
multiple roles assign kiye jaate hain, aur har role ke sath specific permissions associated hoti
hain.

DBMS Me Kaise Kaam Karta Hai - Users ko roles assign kiye jaate hain, aur phir un roles
ke basis par hi access control decisions li jati hain. For example, ek organization mein
"Manager" role ko write access diya ja sakta hai, jabki "Employee" role ko sirf read access diya
ja sakta hai.

Summary
• DAC: Users ke discretion par depend karta hai, jisme data owners control karte hain.
• MAC: Predefined security policies par depend karta hai, jisme data labels aur
predefined rules use hote hain.
• RBAC: Roles ke basis par defined hota hai, jisme users ko specific roles assign kiye
jaate hain aur un roles ke sath associated permissions hoti hain.

Intrusion Detection
Intrusion Detection ka mtlb hota hai kisi bhi unauthorized access, attacks, ya abnormal
activities ko identify karna aur uske against measures lene ka process. Yeh ek crucial part hai
information security ka, jo systems ko protect karta hai against malicious activities. Intrusion
Detection System (IDS) ismein madad karta hai.

Chaliye isko detail mein samjhein:

Intrusion Detection System (IDS):


IDS ek security tool hota hai jo continuously network traffic aur system activities ko monitor
karta hai, taki koi bhi unauthorized access ya security threats ko detect kiya ja sake.

Types of IDS (IDS ke Prakar):


1. Network-Based IDS (NIDS): Network traffic ko monitor karta hai, unusual patterns
ya malicious activities ko detect karne ke liye.
2. Host-Based IDS (HIDS): Individual systems ya devices ko monitor karta hai,
unauthorized access ya malicious activities ko identify karne ke liye.
3. Behavior-Based IDS: Expected behavior ke against anomalies ko detect karta hai,
jaise ki unusual file access patterns ya abnormal network traffic.
[DBMS NOTES BY KHYATI]

4. Signature-Based IDS: Known attack patterns (signatures) ke comparison se detect


karta hai. Yeh predefined signatures use karta hai.
5. Anomaly-Based IDS: System ka normal behavior define karta hai aur uske against
deviations ko identify karta hai.

Working
Monitoring
Analysis
Alerting
Response

Benefits of IDS (IDS ke Fayde):


1. Early Detection
2. Continuous Monitoring
3. Alerts and Notifications
4. Threat Intelligence

SQL injection
SQL injection ek tarah ka security vulnerability hai jisme attacker user input ka galat istemal
karke database ke query ko manipulate kar leta hai. Isse unauthorized access, data badalna ya
dusre nuksan karne ke chances badh jaate hain. Ye web applications ke liye ek common aur
serious threat hai jo SQL queries ka istemal karte hain.

Kaise SQL Injection Kaam Karta Hai

1. User Input in SQL Query:


• Web applications user input ko istemal karke SQL queries banate hain jo database ko
bheji jaati hain.
• Jaise ki login form mein username aur password input fields hote hain, aur query kuch
is tarah ka hota hai:

Ex.
SELECT * FROM users WHERE username = 'input_username' AND password = 'input_password';

2. Malicious Input Injection:


• Attacker user input fields ko manipulate karke web application ko dhoka de sakta hai.
• For example, agar attacker ne username field mein `' OR '1'='1'; --` type kar diya, toh
query aise dikhegi:

SELECT * FROM users WHERE username = '' OR '1'='1'; --' AND password = '';

• Yahan `--` SQL mein ek comment hota hai, isse baaki ka kuch bhi execute nahi hoga.
Isse query hamesha true ho jayegi (`'1'='1'`), aur attacker ko unauthorized access mil
jaayega.
[DBMS NOTES BY KHYATI]

3. SQL Injection ke Asar:


• Unauthorized access: Attacker ko sensitive information tak pahunch sakta hai.
• Data badalna: Database mein data ko modify ya delete kar sakta hai.
• Authentication bypass: SQL injection se login mechanisms ko bypass kiya ja sakta
hai.

Data warehousing
Data warehousing ek process hai jisme hum data ko collect, store, aur manage karte hain ek
centralized location mein, jo hum kehte hain data warehouse. Iska main aim hota hai ki hum
business intelligence aur decision-making ke liye data ko ek jagah par lekar aayein. Chaliye
isko aur detail mein samajhte hain:

Data Warehousing ke Components:


1. Data Sources:
Data warehouse mein data various sources se aata hai jaise operational databases, external data
feeds, spreadsheets, aur aur bhi kai jagah se.

2. ETL (Extract, Transform, Load) Process:


ETL process ka kaam hota hai data ko source systems se extract karna, use ek consistent format
mein transform karna, aur fir data warehouse mein load karna. Isse data saaf, consistent aur
analysis ke liye ready ho jaata hai.

3. Data Warehouse:
Data warehouse ek centralized storage hai jisme data organized tareeke se rakha jaata hai. Yeh
query aur analysis ke liye design hota hai, jisse users complex queries run karke reports
generate kar sakein.

4. Metadata:
Metadata hota hai data warehouse ke baare mein information, jaise ki data ka source, meaning,
format, aur relationships. Yeh users ko data samajhne aur navigate karne mein madad karta hai.

5. OLAP (Online Analytical Processing) aur Data Cubes:


OLAP tools allow karte hain users ko interactively data analyze aur navigate karne mein. Data
cubes, multidimensional format mein data ko represent karte hain, jisse users ko relationships
aur trends explore karne mein asani hoti hai.

Key Concepts:
1. Subject-Oriented:
Data warehousing specific subjects ya business areas par focus karta hai, jaise ki sales, finance,
ya marketing. Isse data ka comprehensive view milta hai.

2. Integrated:
Data warehousing alag-alag sources se aane wala data ek consistent format mein integrate karta
hai. Isse organization ke andar data ka unified view milta hai.
[DBMS NOTES BY KHYATI]

3. Time-Variant:
Data warehousing historical data capture karta hai aur time-based analysis ko support karta hai.
Isse users ko changes aur trends ko track karne mein madad milti hai.

4. Non-Volatile:
Jab data warehouse mein data load ho jaata hai, woh read-only ho jaata hai. Is non-volatile
nature se yeh ensure hota hai ki historical data unchanged rahe aur analysis ke liye stable
environment ho.

Data Warehousing ke Fayde:


1. Improved Decision-Making
2. Efficient Reporting and Analysis
3. Data Quality and Consistency
4. Historical Analysis
5. Enhanced Business Intelligence

Data mining
Data mining ek process hai jisme hum large datasets se patterns, relationships, aur useful
information extract karte hain. Iska main aim hota hai hidden insights aur knowledge ko
discover karna, jo traditional database analysis ke through possible nahi hota. Chaliye isko
detail mein samajhte hain:

Data Mining ke Key Concepts:


1. Pattern Discovery:
Data mining ka primary objective hota hai patterns ko identify karna. Yeh patterns numerical
data, text, images, aur other forms of data par depend karte hain.

2. Types of Patterns:
• Association Rule Mining: Identifying associations or relationships between different
variables in the dataset. For example, people who buy product X are likely to buy
product Y as well.
• Classification: Predicting the category or class of a new item based on past
observations. For instance, predicting whether an email is spam or not.
• Clustering: Grouping similar data points together based on certain features or
characteristics.
• Regression Analysis: Predicting numerical values based on historical data.

3. Data Exploration:
Data mining allows for exploration of data to discover trends, anomalies, and interesting
patterns that might not be immediately apparent.

4. Algorithm Usage:
Various algorithms are used in data mining, such as decision trees, neural networks, clustering
algorithms, and association rule algorithms, depending on the type of analysis required.
[DBMS NOTES BY KHYATI]

5. Data Preprocessing:
Data preprocessing is an essential step in data mining, involving cleaning, transforming, and
organizing the data to ensure accurate and meaningful results.

Applications of Data Mining:


1. Retail Industry:
Recommender systems use data mining to suggest products to customers based on their
preferences and purchase history.

2. Healthcare:
Data mining helps in predicting disease outbreaks, identifying patient trends, and improving
treatment outcomes.

3. Finance:
Fraud detection, credit scoring, and market trend analysis are common applications of data
mining in the financial sector.

4. Telecommunications:
Analyzing call records and customer data helps in improving service quality and identifying
potential issues.

5. Marketing:
Targeted advertising, customer segmentation, and market basket analysis are common uses of
data mining in marketing.

Benefits of Data Mining:


1. Predictive Analysis:
Data mining allows organizations to make predictions about future trends and behaviors based
on historical data.

2. Improved Decision-Making:
By uncovering hidden patterns and relationships, data mining provides valuable insights that
can aid in better decision-making.

3. Customer Retention:
Businesses use data mining to understand customer behavior, preferences, and satisfaction,
which helps in customer retention strategies.

4. Risk Management:
In industries like finance, data mining is crucial for identifying and managing risks associated
with various financial transactions.

5. Operational Efficiency:
Data mining helps in optimizing processes, improving efficiency, and reducing costs by
identifying areas for improvement.
[DBMS NOTES BY KHYATI]

Challenges in Data Mining:


1. Data Quality:
The accuracy and completeness of data are critical for the success of data mining. Poor-quality
data can lead to inaccurate results.

2. Overfitting:
Overfitting occurs when a model is too complex and fits the training data too closely, resulting
in poor performance on new, unseen data.

3. Interpretability:
Some complex data mining models may be difficult to interpret, making it challenging for users
to understand and trust the results.

4. Privacy Concerns:
The use of personal data in data mining raises privacy concerns. Striking a balance between
data utilization and privacy protection is crucial.

You might also like