डेटाबेस को सबसे सरल भाषा में समझो — यह एक व्यवस्थित डिजिटल अलमारी है। जैसे एक बैंक की 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 कब काम करता है और क्यों।
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 हटाता है।
जब दो 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) तक ले जा सकते हो।
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 है।
जब एक साथ कई 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 करो।
| 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 रोकता है।
Distributed Database में एक transaction कई sites पर data modify कर सकती है। यह guarantee करना कि ya to sab sites commit करें, ya sab abort करें — इसके लिए Two-Phase Commit (2PC) है।
Caching = frequently accessed data को fast memory (RAM) में रखो ताकि हर बार disk I/O न करना पड़े। यह data को processor के करीब लाता है।
Indexing = data को तेज़ ढूंढने के लिए एक separate data structure (B+ Tree, Hash) बनाओ।
दोनों performance optimization techniques हैं — लेकिन काम अलग-अलग है।
याद करो: "1 Partial 2 Transitive 3 BCNF"
प्रश्न में "transitive dependency" शब्द दिखे → सीधे 3NF answer करो। Standard approach: पूरी definition याद करने में 40 seconds vs. इस pattern से 5 seconds।
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।
परीक्षा में join algorithm पूछें तो तीन सवाल करो:
इस elimination framework से किसी भी join scenario में 8 seconds में answer मिलता है, बिना algorithms की complexity याद किए।
याद करो: "URRS" — Uncommitted → Committed → Repeatable → Serializable
हर level नीचे वाले की problems ठीक करता है:
"Dirty read allow करे" → READ UNCOMMITTED। बस। Confusion से बाहर निकलने में standard तरीके से 25s vs. URRS pattern से 6s।
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 फिर से देखो।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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)।
क्यों यह प्रश्न: 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।
क्यों यह प्रश्न: 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।
3NF और BCNF की अदला-बदली: "Transitive dependency" सुनते ही BCNF choose कर लेते हो। याद रखो — BCNF "every determinant is a candidate key" के बारे में है। Transitive dependency specifically 3NF का domain है।
READ COMMITTED को Dirty Read वाला मानना: READ COMMITTED dirty read को रोकता है, allow नहीं करता। "Dirty read allow करे" → READ UNCOMMITTED। यह सबसे common wrong answer है।
2PC को 2PL से confuse करना: दोनों में "Two-Phase" है लेकिन context बिल्कुल अलग है। "Distributed + multiple sites + atomicity" = 2PC। "Single DB + locking + serializability" = 2PL।
B+ Tree में Internal Node की formula Leaf पर लगाना: Internal node में max children = m, max keys = (m-1)। Leaf node में भी max keys = (m-1) — same formula, लेकिन अगर exam ने "children" पूछा हो तो Internal Node = m, Leaf = technically leaf में sibling pointer होते हैं। Key count के लिए दोनों = (m-1)।
Hash Join को हमेशा best मानना: Hash Join तभी best है जब एक table दूसरी से काफी छोटी हो और दोनों unsorted हों। अगर data already sorted है → Sort-Merge Join बेहतर। अगर inner table पर index है → Index Nested Loop Join बेहतर।
Caching और Indexing को same समझना: दोनों performance optimization करते हैं लेकिन Caching data को fast memory में copy करता है (disk I/O कम करने के लिए), जबकि Indexing search को fast बनाने के लिए extra data structure रखता है। "Processor के करीब", "fast storage" → Caching। "Search fast करो" → Indexing।