SBI PO के लिए डेटाबेस प्रबंधन की मूल बातें — DBMS, SQL, Normalization

intermediate 22 min read

अवधारणा

डेटाबेस को सबसे सरल भाषा में समझो — यह एक व्यवस्थित डिजिटल अलमारी है। जैसे एक बैंक की physical फाइलें एक कमरे में अलमारियों में, फ़ोल्डरों में, कागज़ों में व्यवस्थित होती हैं — ठीक वैसे ही DBMS (Database Management System) डेटा को tables में, rows में, और columns में स्टोर करता है।

DBMS और RDBMS में फ़र्क यह है कि RDBMS में tables के बीच relationships होते हैं — जैसे एक Customer table और एक Account table आपस में Customer ID से जुड़ी हों। Oracle, MySQL, PostgreSQL, Microsoft SQL Server — ये सब RDBMS के उदाहरण हैं।

एक Relational Database की मूल इकाई है Relation (Table)। हर table में:

Referential Integrity का मतलब है — अगर तुम किसी Foreign Key में कोई value डालते हो, तो वह value उस referenced table में exist करनी चाहिए, या NULL होनी चाहिए। यह constraint orphan records (बेघर records) बनने से रोकता है।

SBI PO में इस topic से प्रश्न सीधे नहीं आते — वे conceptual scenarios देकर पूछते हैं। इसलिए definitions रटने से ज़्यादा ज़रूरी है यह समझना कि कौन सा concept कब काम करता है और क्यों।


गहन विश्लेषण

1. Normalization — Redundancy हटाने की प्रक्रिया

Normalization का मकसद है डेटा को इस तरह organize करना कि:

Normal Forms का क्रम:

| Normal Form | क्या हटाता है | |-------------|---------------| | 1NF | Repeating groups, Non-atomic values | | 2NF | Partial Functional Dependency (Composite Key पर) | | 3NF | Transitive Functional Dependency | | BCNF | 3NF से ज़्यादा strict — हर determinant एक candidate key हो |

Transitive Dependency समझो: मान लो Student_ID → Department → HOD_Name। यहाँ HOD_Name, Student_ID पर indirectly निर्भर है (Department के ज़रिए)। यह 3NF का violation है। Solution: Department और HOD_Name को अलग table में निकालो।

याद रखो — 3NF transitive dependency हटाता है, 2NF partial dependency हटाता है।

2. Join Algorithms — बड़ी Tables को कैसे मिलाएं

जब दो tables को join करना हो, तो algorithm का चुनाव data के आकार और state पर निर्भर करता है:

Nested Loop Join: सबसे सरल — एक table के हर row के लिए दूसरी table पूरी scan करो। Small tables के लिए ठीक है, large tables के लिए O(n×m) — बहुत धीमा।

Hash Join: एक table (छोटी वाली) से hash table बनाओ, फिर बड़ी table को scan करके matches ढूंढो। Complexity: O(n+m)। Unsorted, large tables के लिए सबसे efficient। Memory में hash table fit होनी चाहिए।

Sort-Merge Join: दोनों tables को पहले sort करो, फिर merge करो। अगर data पहले से sorted हो तो बेहतरीन। अन्यथा sorting का overhead लगता है।

Index Nested Loop Join: अगर inner table पर index हो तो Nested Loop को O(n × log m) तक ले जा सकते हो।

3. B+ Tree Index

B+ Tree indexing में order (m) एक node में maximum children की संख्या बताता है।

Order 5 B+ Tree → Leaf Node में अधिकतम keys = 5-1 = 4

Leaf nodes में actual data records के pointers होते हैं, और सभी leaf nodes एक linked list से जुड़े होते हैं — इसीलिए range queries के लिए B+ Tree बेहद efficient है।

4. Concurrency Control

जब एक साथ कई transactions चलें, तो data consistency बनाए रखने के लिए Concurrency Control चाहिए।

Two-Phase Locking (2PL): Growing Phase (locks acquire करो) और Shrinking Phase (locks release करो)। Serializability guarantee करता है।

Timestamp Ordering Protocol: हर transaction को एक unique timestamp मिलता है। यह timestamp decide करता है कि conflicting operations किस क्रम में execute होंगे। कोई lock नहीं लगता — timestamps से ही order तय होता है।

Multiversion Concurrency Control (MVCC): हर data item के multiple versions maintain करता है। Readers writers को block नहीं करते।

Optimistic Concurrency Control: Assume करो कि conflicts नहीं होंगे। Transaction के end में validate करो।

5. SQL Isolation Levels

| Level | Dirty Read | Non-Repeatable Read | Phantom Read | |-------|-----------|---------------------|--------------| | READ UNCOMMITTED | Allowed | Allowed | Allowed | | READ COMMITTED | Prevented | Allowed | Allowed | | REPEATABLE READ | Prevented | Prevented | Allowed | | SERIALIZABLE | Prevented | Prevented | Prevented |

Dirty Read = uncommitted data पढ़ना। READ UNCOMMITTED इसकी अनुमति देता है, लेकिन basic locking से lost updates रोकता है।

6. Two-Phase Commit Protocol (Distributed DB)

Distributed Database में एक transaction कई sites पर data modify कर सकती है। यह guarantee करना कि ya to sab sites commit करें, ya sab abort करें — इसके लिए Two-Phase Commit (2PC) है।

7. Caching vs Indexing

Caching = frequently accessed data को fast memory (RAM) में रखो ताकि हर बार disk I/O न करना पड़े। यह data को processor के करीब लाता है।

Indexing = data को तेज़ ढूंढने के लिए एक separate data structure (B+ Tree, Hash) बनाओ।

दोनों performance optimization techniques हैं — लेकिन काम अलग-अलग है।


शॉर्टकट और युक्तियाँ

patternNormal Form सीढ़ी — नीचे से ऊपर

याद करो: "1 Partial 2 Transitive 3 BCNF"

  • 1NF → atomic values
  • 2NF → partial dependency हटाओ (1NF + No Partial)
  • 3NF → transitive dependency हटाओ (2NF + No Transitive)
  • BCNF → हर determinant candidate key हो (3NF से strict)

प्रश्न में "transitive dependency" शब्द दिखे → सीधे 3NF answer करो। Standard approach: पूरी definition याद करने में 40 seconds vs. इस pattern से 5 seconds।

patternB+ Tree Leaf Keys = Order minus 1

Order m → Leaf nodes में max keys = (m-1)

परीक्षा में अक्सर confusion होती है कि internal node की formula लगा दो। Internal node में भी max keys = (m-1), लेकिन children = m। Leaf node में children नहीं होते — सिर्फ keys और data pointers।

Order 5 → 5-1 = 4. Order 7 → 7-1 = 6. बस। Standard method: formula derive करने में 30s vs. direct rule: 5s।

eliminationJoin Algorithm चुनाव — 3 सवालों का rule

परीक्षा में join algorithm पूछें तो तीन सवाल करो:

  1. क्या दोनों tables sorted हैं? → Yes → Sort-Merge Join
  2. क्या inner table पर index है? → Yes → Index Nested Loop Join
  3. क्या एक table बहुत छोटी है, दोनों unsorted हैं? → Yes → Hash Join
  4. बाकी सब cases / small data → Nested Loop Join

इस elimination framework से किसी भी join scenario में 8 seconds में answer मिलता है, बिना algorithms की complexity याद किए।

patternIsolation Levels — नीचे से ऊपर बढ़ती strictness

याद करो: "URRS" — Uncommitted → Committed → Repeatable → Serializable

हर level नीचे वाले की problems ठीक करता है:

  • UNCOMMITTED: सब problems allow
  • COMMITTED: dirty read ठीक
  • REPEATABLE: dirty + non-repeatable ठीक
  • SERIALIZABLE: तीनों problems ठीक

"Dirty read allow करे" → READ UNCOMMITTED। बस। Confusion से बाहर निकलने में standard तरीके से 25s vs. URRS pattern से 6s।

pattern2PC vs 2PL — नाम में ही जवाब

2PC (Two-Phase Commit) = Distributed database में atomicity के लिए — "Commit" शब्द है, distributed context है।

2PL (Two-Phase Locking) = Single database में serializability के लिए — "Locking" शब्द है, concurrency context है।

Exam में अगर "distributed database", "multiple sites", "atomicity across sites" दिखे → 2PC। अगर "serializability", "concurrent transactions", "lock" दिखे → 2PL। Standard confusion में 20s vs. context-keyword matching: 4s।


तेज़-समाधान रूपरेखा

परीक्षा में DBMS का प्रश्न देखते ही यह mental decision tree चलाओ:

Step 1 — Topic identify करो:

Step 2 — Keyword trap से बचो:

Step 3 — एक line में answer confirm करो: हर answer को एक वाक्य में justify करो — अगर नहीं कर सकते तो option फिर से देखो।


हल किए गए PYQs

क्यों यह प्रश्न: Join algorithms का conceptual understanding SBI PO में directly test होता है। Real-world scenarios देकर पूछते हैं — theory नहीं।

समाधान का रास्ता: दोनों tables unsorted हैं → Sort-Merge eliminate। एक table छोटी है → Hash Join के लिए ideal scenario। Hash table छोटी table से बनाओ (memory में fit), बड़ी table scan करो। O(n+m) complexity।

Previous Year Questionपिछले वर्ष का प्रश्न
Which join algorithm would be most efficient for joining two large tables where one table is significantly smaller than the other and both are unsorted?
दो बड़ी टेबल्स को जॉइन करने के लिए कौन सा जॉइन एल्गोरिदम सबसे ज्यादा कारगर होगा, जब एक टेबल दूसरे से काफी छोटी हो और दोनों अनसॉर्टेड हों?
  1. Nested Loop Join
  2. Hash Join
  3. Sort-Merge Join
  4. Index Nested Loop Join
  1. Nested Loop Join
  2. Hash Join
  3. Sort-Merge Join
  4. Index Nested Loop Join
Solutionसमाधान
Hash Join is most efficient for this scenario because it builds a hash table from the smaller relation (probe relation) and then scans the larger relation to find matches. This approach has O(n+m) complexity and doesn't require sorted input.
हैश जॉइन इस स्थिति के लिए सबसे कुशल है क्योंकि यह छोटे रिलेशन (प्रोब रिलेशन) से हैश टेबल बनाता है और फिर बड़े रिलेशन को स्कैन करके मैचेस ढूंढता है। इस तरीके की कॉम्प्लेक्सिटी O(n+m) है और इसे सॉर्ट किए गए इनपुट की ज़रूरत नहीं।

क्यों यह प्रश्न: B+ Tree की leaf node capacity एक classic trap question है। Order और max keys का relationship confuse करना आसान है।

समाधान का रास्ता: Order 5 → max keys in leaf = 5-1 = 4। Internal node में भी (m-1) keys होती हैं लेकिन m children होते हैं। Leaf node में children नहीं होते। Answer: 4।

Previous Year Questionपिछले वर्ष का प्रश्न
In a B+ tree index with order 5, what is the maximum number of keys that can be stored in a leaf node?
ऑर्डर 5 वाले B+ ट्री इंडेक्स में एक लीफ नोड में अधिकतम कितनी keys स्टोर की जा सकती हैं?
  1. 4
  2. 5
  3. 6
  4. 10
  1. 4
  2. 5
  3. 6
  4. 10
Solutionसमाधान
In a B+ tree of order m, a leaf node can contain at most (m-1) keys. For order 5, the maximum number of keys in a leaf node is 5-1 = 4. The order determines the maximum number of children a node can have.
ऑर्डर m के B+ ट्री में, एक लीफ नोड में अधिकतम (m-1) कुंजियां हो सकती हैं। ऑर्डर 5 के लिए, लीफ नोड में अधिकतम कुंजियों की संख्या 5-1 = 4 है।

क्यों यह प्रश्न: Concurrency control के चारों protocols में से सही एक चुनना — नाम की similarity से confusion होती है।

समाधान का रास्ता: Question में "timestamp" और "order transactions" दोनों शब्द हैं → सीधे Timestamp Ordering Protocol। 2PL locks use करता है timestamps नहीं। MVCC versions maintain करता है। Optimistic assume करता है कि conflicts नहीं होंगे। Answer: Timestamp Ordering Protocol।

Previous Year Questionपिछले वर्ष का प्रश्न
Which concurrency control technique uses timestamps to order transactions and resolve conflicts?
कौन सी कंकरेंसी कंट्रोल तकनीक ट्रांज़ैक्शन को क्रम में लगाने और कॉन्फ्लिक्ट सुलझाने के लिए टाइमस्टैम्प का उपयोग करती है?
  1. Two-Phase Locking
  2. Multiversion Concurrency Control
  3. Timestamp Ordering Protocol
  4. Optimistic Concurrency Control
  1. Two-Phase Locking
  2. Multiversion Concurrency Control
  3. Timestamp Ordering Protocol
  4. Optimistic Concurrency Control
Solutionसमाधान
Timestamp Ordering Protocol uses timestamps assigned to transactions to determine the order of execution and resolve conflicts. Each transaction gets a unique timestamp, and operations are executed in timestamp order to maintain serializability.
टाइमस्टैम्प ऑर्डरिंग प्रोटोकॉल लेनदेन को असाइन किए गए टाइमस्टैम्प का उपयोग करके निष्पादन क्रम निर्धारित करता है और संघर्षों को हल करता है।

क्यों यह प्रश्न: Isolation levels की table का ज्ञान — "allow करता है लेकिन रोकता है" वाली phrasing trap है।

समाधान का रास्ता: Dirty read allow करे → READ UNCOMMITTED (URRS pattern में सबसे नीचे)। Lost updates basic locking से रुकते हैं। READ COMMITTED dirty read रोकता है — यह wrong है। Answer: READ UNCOMMITTED।

Previous Year Questionपिछले वर्ष का प्रश्न
Which SQL isolation level allows dirty reads but prevents lost updates?
कौन सा SQL आइसोलेशन लेवल dirty reads की अनुमति देता है लेकिन lost updates को रोकता है?
  1. READ UNCOMMITTED
  2. READ COMMITTED
  3. REPEATABLE READ
  4. SERIALIZABLE
  1. READ UNCOMMITTED
  2. READ COMMITTED
  3. REPEATABLE READ
  4. SERIALIZABLE
Solutionसमाधान
READ UNCOMMITTED is the lowest isolation level that allows dirty reads (reading uncommitted changes from other transactions) but still prevents lost updates through basic locking mechanisms. It provides minimal isolation but maximum concurrency.
READ UNCOMMITTED सबसे कम अलगाव स्तर है जो डर्टी रीड्स की अनुमति देता है लेकिन बुनियादी लॉकिंग तंत्र के माध्यम से खोए हुए अपडेट्स को रोकता है।

क्यों यह प्रश्न: Distributed database में atomicity — 2PC और 2PL का नाम-based confusion यहाँ directly test होता है।

समाधान का रास्ता: "Distributed database", "multiple sites", "commit or abort on all sites" → यह 2PC का exact definition है। 2PL single database में serializability के लिए है। Timestamp Ordering और Optimistic CC distributed atomicity guarantee नहीं देते। Answer: Two-Phase Commit Protocol।

Previous Year Questionपिछले वर्ष का प्रश्न
In a distributed database system, which technique is used to ensure that a transaction either commits at all sites or aborts at all sites?
एक डिस्ट्रिब्यूटेड डेटाबेस सिस्टम में, यह सुनिश्चित करने के लिए कि कोई ट्रांजेक्शन या तो सभी साइट्स पर कमिट हो या सभी पर अबॉर्ट हो, कौन सी तकनीक का उपयोग किया जाता है?
  1. Two-Phase Locking Protocol
  2. Two-Phase Commit Protocol
  3. Timestamp Ordering Protocol
  4. Optimistic Concurrency Control
  1. Two-Phase Locking Protocol
  2. Two-Phase Commit Protocol
  3. Timestamp Ordering Protocol
  4. Optimistic Concurrency Control
Solutionसमाधान
The Two-Phase Commit Protocol is specifically designed for distributed databases to ensure atomicity across multiple sites. It involves a coordinator that manages the commit process in two phases: prepare phase and commit phase.
टू-फेज कमिट प्रोटोकॉल विशेष रूप से वितरित डेटाबेस के लिए डिज़ाइन किया गया है ताकि कई साइटों में परमाणुता सुनिश्चित की जा सके। इसमें एक समन्वयक होता है जो दो चरणों में कमिट प्रक्रिया का प्रबंधन करता है।

क्यों यह प्रश्न: Normal forms में से specific dependency का सही form चुनना — BCNF और 3NF की confusion यहाँ test होती है।

समाधान का रास्ता: "Transitive functional dependency" → 3NF। BCNF 3NF से ज़्यादा strict है लेकिन वह specifically transitive dependency के लिए नहीं है — वह every determinant को candidate key बनाता है। Answer: Third Normal Form (3NF)।

Previous Year Questionपिछले वर्ष का प्रश्न
Which normal form specifically addresses the issue of transitive functional dependencies in relational database design?
रिलेशनल डेटाबेस डिज़ाइन में ट्रांज़िटिव फंक्शनल डिपेंडेंसी की समस्या को खास तौर पर कौन-सा नॉर्मल फॉर्म हल करता है?
  1. Fourth Normal Form (4NF)
  2. Boyce-Codd Normal Form (BCNF)
  3. Second Normal Form (2NF)
  4. Third Normal Form (3NF)
  1. Fourth Normal Form (4NF)
  2. Boyce-Codd Normal Form (BCNF)
  3. Second Normal Form (2NF)
  4. Third Normal Form (3NF)
Solutionसमाधान
Third Normal Form (3NF) eliminates transitive functional dependencies, where a non-prime attribute depends on another non-prime attribute that depends on the primary key. This prevents redundancy and update anomalies.
तीसरा सामान्य रूप (3NF) पारगामी कार्यात्मक निर्भरताओं को समाप्त करता है, जहाँ एक गैर-प्राथमिक गुण दूसरे गैर-प्राथमिक गुण पर निर्भर करता है जो प्राथमिक कुंजी पर निर्भर है। यह अनावश्यकता और अद्यतन विसंगतियों को रोकता है।

क्यों यह प्रश्न: Integrity constraints में से सही constraint identify करना — चारों options के names confusing हैं।

समाधान का रास्ता: Foreign key की value या तो referenced table की Primary Key से match करे या NULL हो — यह definition ही Referential Integrity Constraint की है। Entity Integrity कहती है Primary Key NULL नहीं हो सकती। Check Constraint user-defined condition है। Domain Integrity data type/range के बारे में है। Answer: Referential Integrity Constraint।

Previous Year Questionपिछले वर्ष का प्रश्न
In a relational database, which constraint ensures that a foreign key value either matches a primary key value in the referenced table or is NULL?
रिलेशनल डेटाबेस में कौन-सा कंस्ट्रेंट यह सुनिश्चित करता है कि फॉरेन की की वैल्यू या तो रेफर्ड टेबल की प्राइमरी की से मेल खाए या NULL हो?
  1. Entity Integrity Constraint
  2. Referential Integrity Constraint
  3. Check Constraint
  4. Domain Integrity Constraint
  1. Entity Integrity Constraint
  2. Referential Integrity Constraint
  3. Check Constraint
  4. Domain Integrity Constraint
Solutionसमाधान
Referential Integrity Constraint ensures that foreign key values must either reference existing primary key values in the parent table or be NULL. This maintains logical consistency between related tables and prevents orphaned records.
संदर्भात्मक अखंडता बाधा सुनिश्चित करती है कि विदेशी कुंजी मान या तो मूल तालिका में मौजूदा प्राथमिक कुंजी मानों का संदर्भ देते हैं या NULL होते हैं। यह संबंधित तालिकाओं के बीच तार्किक स्थिरता बनाए रखता है और अनाथ रिकॉर्ड को रोकता है।

क्यों यह प्रश्न: Performance optimization techniques में Caching और Indexing को distinguish करना — दोनों performance बढ़ाते हैं लेकिन अलग तरीके से।

समाधान का रास्ता: "Frequently accessed data", "processor के करीब", "faster storage media" → ये सब Caching के keywords हैं। Indexing fast search के लिए अलग data structure बनाता है — data को move नहीं करता। Normalization redundancy हटाता है। Partitioning data को pieces में बाँटता है। Answer: Caching।

Previous Year Questionपिछले वर्ष का प्रश्न
Which database optimization technique involves storing frequently accessed data in faster storage media closer to the processor?
डेटाबेस ऑप्टिमाइज़ेशन की किस तकनीक में बार-बार एक्सेस होने वाले डेटा को प्रोसेसर के करीब तेज़ स्टोरेज मीडिया में स्टोर किया जाता है?
  1. Indexing
  2. Caching
  3. Normalization
  4. Partitioning
  1. Indexing
  2. Caching
  3. Normalization
  4. Partitioning
Solutionसमाधान
Caching stores frequently accessed data in faster memory (like RAM) or storage media closer to the processor to reduce access time. This optimization technique significantly improves database performance by avoiding repeated expensive disk I/O operations.
कैशिंग पहुंच समय को कम करने के लिए बार-बार एक्सेस किए गए डेटा को तेज़ मेमोरी (जैसे RAM) या प्रोसेसर के करीब स्टोरेज मीडिया में संग्रहीत करती है। यह अनुकूलन तकनीक बार-बार होने वाले महंगे डिस्क I/O संचालन से बचकर डेटाबेस प्रदर्शन को काफी बेहतर बनाती है।

आम गलतियाँ


संबंधित विषय

SarkariRise पर अभ्यास

Sign up + get 3 free mocks →