Foreign Key: Referential Integrity Constraint and Foreign Key Rules Notes in Hindi & English : फॉरेन की (Foreign Key): संदर्भात्मक अखंडता (Referential Integrity) नियम और 20 महत्वपूर्ण MCQ प्रश्न (Rajasthan IT Exam)

Post a Comment

PGDCA, BCA, B-Tech, MCA, M-Tech, B.Sc computer science राजस्थान सूचना सहायक व कंप्यूटर शिक्षक विशेष नोट्स: इस अध्याय में हम Foreign Key: Referential Integrity Constraint and Foreign Key Rules (फॉरेन की (Foreign Key): संदर्भात्मक अखंडता (Referential Integrity) नियम) की संपूर्ण थ्योरी, मुख्य तकनीकी बिंदु, तुलनात्मक तालिका और विगत परीक्षाओं के पैटर्न पर आधारित 20 अति-महत्वपूर्ण बहुविकल्पीय प्रश्न (MCQs) विस्तृत हिंदी व अंग्रेजी व्याख्या सहित पढ़ेंगे।

Overview: A Foreign Key (FK) is an attribute or attribute set in a referencing (child) relation whose non-null values must match an existing Candidate/Primary Key value in a referenced (parent) relation. Together with SQL referential actions (RESTRICT, CASCADE, SET NULL, SET DEFAULT), it enforces Referential Integrity and prevents orphan records.

अध्याय सार: फॉरेन की (Foreign Key) चाइल्ड टेबल का वह एट्रिब्यूट या एट्रिब्यूट समूह है जिसका गैर-नल (Non-Null) मान पैरेंट टेबल की प्राइमरी की (या यूनिक की) के किसी मौजूदा मान से मेल खाना अनिवार्य होता है। यह संदर्भात्मक अखंडता (Referential Integrity) लागू कर अनाथ (Orphan) रिकॉर्ड्स बनने से रोकता है।

Foreign Key: Referential Integrity Constraint and Foreign Key Rules: Detailed Notes & Architecture (फॉरेन की (Foreign Key): संदर्भात्मक अखंडता (Referential Integrity) नियम)

1. Foreign Key Definition, Self-Referencing & NULL/Duplicate Rules (फॉरेन की की परिभाषा, स्व-संदर्भ और NULL/डुप्लीकेट नियम)

[EN] A Foreign Key in child relation R1 links R1 to parent relation R2 by matching R2's Primary Key (or any UNIQUE Candidate Key). Critically, unlike a Primary Key: (1) a Foreign Key CAN contain duplicate values (many employees share the same Dept_ID = 10 in a 1:N relation); (2) a Foreign Key CAN contain NULL values unless explicitly marked NOT NULL; and (3) R1 and R2 can be the exact SAME table—creating a Self-Referencing (Recursive) Foreign Key such as Employee(Mgr_ID) referencing Employee(Emp_ID). Note also that column names need NOT match between child and parent, only their data types/domains must match.

[HI] फॉरेन की एक टेबल को दूसरी टेबल की प्राइमरी की (या UNIQUE की) से जोड़ती है। प्राइमरी की के विपरीत, फॉरेन की में (1) डुप्लीकेट मान आ सकते हैं (जैसे एक ही विभाग के कई कर्मचारी), (2) फॉरेन की में NULL मान हो सकता है (यदि NOT NULL न लगा हो), और (3) चाइल्ड व पैरेंट एक ही टेबल हो सकते हैं जिसे स्व-संदर्भित (Self-Referencing) फॉरेन की कहते हैं। चाइल्ड व पैरेंट कॉलम के नाम अलग हो सकते हैं, परंतु उनका डेटा टाइप समान होना आवश्यक है।

2. Referential Integrity Constraint & Modification Operations (संदर्भात्मक अखंडता (Referential Integrity) और DML प्रभाव)

[EN] Referential Integrity guarantees no 'dangling references' or orphan child tuples exist—every non-null Foreign Key in R1 must point to a valid tuple currently present in R2. Examine the 4 DML risks: (1) INSERT into Parent: ALWAYS safe; (2) INSERT into Child: violates RI if non-null FK doesn't exist in Parent (rejected); (3) DELETE from Child: ALWAYS safe; (4) DELETE from Parent or UPDATE Parent's PK: CAN violate RI if matching Child rows exist! Updating a Child's FK to an invalid parent ID is also rejected.

[HI] संदर्भात्मक अखंडता सुनिश्चित करती है कि चाइल्ड टेबल में कोई 'अनाथ रिकॉर्ड' न हो जिसका पैरेंट मौजूद न हो। चारों DML क्रियाओं का प्रभाव समझें: पैरेंट में INSERT या चाइल्ड से DELETE कभी अखंडता नहीं तोड़ता; परंतु चाइल्ड में अमान्य फॉरेन की INSERT करना, पैरेंट की ऐसी पंक्ति DELETE करना जिसके चाइल्ड मौजूद हों, या पैरेंट की प्राइमरी की UPDATE करना संदर्भात्मक अखंडता का उल्लंघन कर सकता है।

3. SQL Referential Actions: RESTRICT, NO ACTION, CASCADE, SET NULL, SET DEFAULT (SQL में उल्लंघन प्रबंधन नियम (ON DELETE / ON UPDATE))

[EN] When a Parent row is deleted or its PK updated while Child rows reference it, SQL handles the conflict using four referential actions specified via ON DELETE / ON UPDATE: (1) RESTRICT / NO ACTION (default)—aborts and rejects the parent deletion/update if child matches exist; (2) CASCADE—automatically deletes (or updates) all matching child rows alongside the parent; (3) SET NULL—keeps child rows alive by replacing their FK with NULL (fails if child FK is NOT NULL); (4) SET DEFAULT—replaces child FK with its declared DEFAULT parent ID.

[HI] जब पैरेंट रिकॉर्ड हटाने या अपडेट करने से चाइल्ड रिकॉर्ड प्रभावित हो, तो SQL चार क्रियाएं प्रदान करता है: (1) RESTRICT / NO ACTION (डिफ़ॉल्ट)—यदि चाइल्ड मौजूद हों तो पैरेंट को हटाने/बदलने से रोक देता है; (2) CASCADE—पैरेंट हटते ही सभी संबंधित चाइल्ड पंक्तियाँ स्वतः हट (या अपडेट हो) जाती हैं; (3) SET NULL—चाइल्ड की फॉरेन की को NULL कर देता है (इसके लिए FK पर NOT NULL नहीं होना चाहिए); (4) SET DEFAULT—FK में डिफ़ॉल्ट मान भर देता है।

4. Composite Foreign Keys & Multi-Column NULL Semantics (कंपोजिट फॉरेन की और SQL में आंशिक NULL व्यवहार)

[EN] If a parent table has a Composite Primary Key (A, B), the referencing child table must define a Composite Foreign Key FOREIGN KEY (x, y) REFERENCES Parent(A, B) with matching column order and types. An intriguing SQL standard nuance arises if a child row holds a partial NULL in a composite FK like (10, NULL): under default SQL MATCH SIMPLE semantics, if ANY column of a composite FK is NULL, the referential check is bypassed and the row is allowed! Defining NOT NULL on all composite FK columns prevents accidental bypass.

[HI] यदि पैरेंट टेबल की प्राइमरी की कंपोजिट (A, B) हो, तो चाइल्ड में भी समान प्रकार के दो कॉलमों की कंपोजिट फॉरेन की FOREIGN KEY (x, y) REFERENCES Parent(A, B) बनानी पड़ती है। SQL के डिफ़ॉल्ट MATCH SIMPLE नियम के तहत यदि कंपोजिट फॉरेन की के किसी एक कॉलम में भी NULL हो (जैसे (10, NULL)), तो डेटाबेस संदर्भात्मक जांच छोड़ देता है; इसलिए सख्त सुरक्षा हेतु सभी FK कॉलमों पर NOT NULL लगाना बेहतर रहता है।

Syntax, Formula & Technical Example (Foreign Key: Referential Integrity Constraint and Foreign Key Rules)

CREATE TABLE Department (Dept_ID INT PRIMARY KEY, DName VARCHAR(40));

CREATE TABLE Employee (
    Emp_ID  INT PRIMARY KEY,
    EName   VARCHAR(50) NOT NULL,
    Dept_ID INT DEFAULT 1,
    Mgr_ID  INT NULL, -- Self-referencing FK (CEO has NULL Mgr_ID)
    CONSTRAINT fk_dept FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID)
        ON DELETE SET NULL ON UPDATE CASCADE,
    CONSTRAINT fk_mgr  FOREIGN KEY (Mgr_ID)  REFERENCES Employee(Emp_ID)
        ON DELETE SET NULL
);

Foreign Key: Referential Integrity Constraint and Foreign Key Rules Quick Reference & Comparison Table

Referential Action (Parent Change)Execution Behavior on Child RowsPrerequisite / Exam Caveat
RESTRICT / NO ACTIONRejects parent DELETE/UPDATE if children existDefault SQL behavior when no action specified
CASCADEPropagates DELETE/UPDATE down to child rowsEssential for Weak Entity existence dependency
SET NULLReplaces orphaned child FK values with NULLFails if child FK column is declared NOT NULL
SET DEFAULTSets orphaned child FK to declared DEFAULTDefault value itself must exist in Parent PK

Foreign Key: Referential Integrity Constraint and Foreign Key Rules Top 20 Bilingual MCQs with Answers

Q1. What does the Referential Integrity Constraint enforce between two tables?

(दो टेबल्स के बीच संदर्भात्मक अखंडता (Referential Integrity) प्रतिबंध क्या सुनिश्चित करता है?)

(A) Every Primary Key column must allow NULLs

(B) Column names in both tables must be spelled identically

(C) Child table must always have fewer rows than parent table

(D) Every non-null Foreign Key value in the child table must match an existing key value in the parent table

Correct Answer: (D)

[EN] Referential integrity prevents dangling references by ensuring non-null FKs point to valid parent tuples.

[HI] यह सुनिश्चित करता है कि चाइल्ड टेबल की प्रत्येक गैर-नल फॉरेन की पैरेंट टेबल के किसी वैध मौजूदा रिकॉर्ड से मेल खाती हो।

Q2. Which of the following operations can NEVER cause a Referential Integrity violation between Parent P and Child C (where C references P)?

(पैरेंट टेबल P और चाइल्ड टेबल C (जहाँ C की फॉरेन की P को संदर्भित करती है) के बीच कौन सा ऑपरेशन कभी भी संदर्भात्मक अखंडता भंग नहीं कर सकता?)

(A) DELETE a row from Parent P

(B) INSERT a row with non-null FK into Child C

(C) INSERT a new valid row into Parent P (or DELETE a row from Child C)

(D) UPDATE the Primary Key inside Parent P

Correct Answer: (C)

[EN] Adding a new parent or removing a child never creates an orphan pointer in Child C.

[HI] पैरेंट टेबल में नई रो जोड़ने (INSERT into P) या चाइल्ड से रो हटाने (DELETE from C) से कोई अनाथ संदर्भ नहीं बन सकता।

Q3. Can a Foreign Key column contain NULL values and duplicate values?

(क्या किसी फॉरेन की (Foreign Key) कॉलम में NULL मान और डुप्लीकेट मान आ सकते हैं?)

(A) No—Foreign Keys strictly forbid NULL values always

(B) Yes—a Foreign Key allows BOTH duplicate values and NULLs (unless restricted by UNIQUE / NOT NULL)

(C) No—Foreign Keys strictly forbid duplicates like Primary Keys

(D) Duplicates are forbidden, though NULL is allowed

Correct Answer: (B)

[EN] In 1:N relationships many children share the same parent FK (duplicates), and optional relationships allow NULL FKs.

[HI] हाँ, फॉरेन की में डुप्लीकेट मान (जैसे एक विभाग के कई कर्मचारी) और NULL मान (वैकल्पिक संबंध में) दोनों आ सकते हैं।

Q4. What is the default referential action in standard SQL if you write FOREIGN KEY (Dept_ID) REFERENCES Department(Dept_ID) without specifying ON DELETE?

(यदि SQL में ON DELETE न लिखा जाए, तो किसी रेफरेंस्ड पैरेंट रो को डिलीट करने पर डिफ़ॉल्ट रूप से क्या कार्रवाई होती है?)

(A) CASCADE (automatically deletes all child rows)

(B) SET DEFAULT

(C) SET NULL

(D) NO ACTION / RESTRICT (rejects the parent deletion if matching child rows exist)

Correct Answer: (D)

[EN] By default, SQL protects child records by refusing to delete a parent that is still referenced.

[HI] डिफ़ॉल्ट रूप से SQL पैरेंट को डिलीट होने से रोक देता है (RESTRICT / NO ACTION) यदि चाइल्ड टेबल में उससे जुड़े रिकॉर्ड हों।

Q5. What happens if ON DELETE SET NULL is attached to a Foreign Key column that is also declared NOT NULL?

(यदि किसी NOT NULL फॉरेन की कॉलम पर ON DELETE SET NULL लगाया जाए और पैरेंट रो हटाने का प्रयास हो, तो क्या होगा?)

(A) The child FK turns into 0

(B) Error / rejection (the DBMS cannot write NULL into a NOT NULL column, or rejects DDL creation)

(C) The NOT NULL constraint is silently deleted

(D) Child rows are deleted instead

Correct Answer: (B)

[EN] SET NULL conflicts with NOT NULL because replacing the FK with NULL violates the NOT NULL domain/entity rule.

[HI] NOT NULL कॉलम में NULL नहीं भरा जा सकता, अतः यह नियम परस्पर विरोधाभासी होने से त्रुटि उत्पन्न करेगा।

Q6. Suppose Department(Dept_ID) has row (10, 'IT'), Employee(Emp_ID, Dept_ID) has (1, 10) and (2, 10) with ON DELETE CASCADE. What happens upon DELETE FROM Department WHERE Dept_ID = 10?

(यदि Employee में Dept_ID पर ON DELETE CASCADE लगा हो, तो Department से Dept_ID = 10 हटाने पर क्या होगा?)

(A) Only Department 10 is deleted while Employees keep Dept_ID = 10

(B) Employees 1 and 2 have Dept_ID set to NULL

(C) Department 10 AND Employees 1 and 2 are all automatically deleted

(D) Deletion is blocked with an error

Correct Answer: (C)

[EN] ON DELETE CASCADE propagates deletion down to every matching child tuple in Employee.

[HI] ON DELETE CASCADE के कारण विभाग 10 के साथ-साथ कर्मचारी 1 और 2 के रिकॉर्ड भी स्वतः डिलीट हो जाएंगे।

Q7. What is a Self-Referencing (Recursive) Foreign Key?

(स्व-संदर्भित (Self-Referencing / Recursive) फॉरेन की क्या होती है?)

(A) A Foreign Key that automatically updates itself to random values

(B) A Primary Key copied without any constraint

(C) A Foreign Key that references the Primary Key (or Unique Key) of the SAME table (e.g., Employee.Mgr_ID -> Employee.Emp_ID)

(D) A Foreign Key referencing two different databases

Correct Answer: (C)

[EN] Unary relationships like employee-manager hierarchies map to a Foreign Key pointing back to the same table's PK.

[HI] जब किसी टेबल की फॉरेन की उसी टेबल की प्राइमरी की को संदर्भित करे (जैसे Employee टेबल में Mgr_ID -> Emp_ID), तो इसे सेल्फ-रेफरेंसिंग FK कहते हैं।

Q8. Must a Foreign Key column have the exact same column NAME as the referenced Primary Key column in the parent table?

(क्या फॉरेन की कॉलम का नाम पैरेंट टेबल की प्राइमरी की कॉलम के नाम से बिल्कुल समान होना अनिवार्य है?)

(A) Yes—otherwise joins fail permanently

(B) Yes—SQL strictly throws an error if names differ

(C) No—names can differ (e.g., Mgr_ID referencing Emp_ID), though their data types/domains must be compatible

(D) Only in composite keys

Correct Answer: (C)

[EN] Only matching data type and semantic domain matter; column names frequently differ (e.g., Author_ID -> User_ID).

[HI] नहीं—कॉलम का नाम अलग हो सकता है (जैसे Mgr_ID और Emp_ID), परंतु दोनों का डेटा टाइप व डोमेन संगत होना जरूरी है।

Q9. If a Foreign Key references a parent column that is NOT the Primary Key, what constraint MUST exist on that parent column?

(यदि फॉरेन की पैरेंट टेबल के किसी ऐसे कॉलम को संदर्भित कर रही है जो प्राइमरी की नहीं है, तो पैरेंट कॉलम पर कौन सा प्रतिबंध होना अनिवार्य है?)

(A) No constraint is needed on the parent column

(B) CHECK (col > 0)

(C) UNIQUE constraint (it must be a Candidate/Alternate Key)

(D) DEFAULT 0

Correct Answer: (C)

[EN] Every foreign key must point to a unique identifier (either PRIMARY KEY or a UNIQUE key) so parent lookups are unambiguous.

[HI] पैरेंट टेबल के संदर्भित कॉलम पर कम से कम UNIQUE प्रतिबंध (अर्थात कैंडिडेट की) होना अनिवार्य है।

Q10. What happens when you execute ON UPDATE CASCADE on a Foreign Key and update a Parent table's Primary Key from 10 to 99?

(यदि फॉरेन की पर ON UPDATE CASCADE लगा हो और पैरेंट टेबल में ID को 10 से बदलकर 99 कर दिया जाए, तो क्या होगा?)

(A) Child rows keep 10, breaking consistency

(B) All child rows holding FK = 10 automatically update their FK to 99

(C) The update fails with a violation error

(D) Child rows are deleted permanently

Correct Answer: (B)

[EN] ON UPDATE CASCADE updates child foreign keys to match the modified parent primary key.

[HI] ON UPDATE CASCADE के चलते चाइल्ड टेबल की उन सभी पंक्तियों में भी मान 10 से बदलकर 99 हो जाएगा।

Q11. Which referential action requires that the child Foreign Key column's DEFAULT value already exist as a valid row in the Parent table?

(किस रेफरेंशियल एक्शन में चाइल्ड की फॉरेन की का DEFAULT मान पहले से पैरेंट टेबल में मौजूद होना आवश्यक है?)

(A) ON DELETE CASCADE

(B) ON DELETE RESTRICT

(C) ON DELETE SET NULL

(D) ON DELETE SET DEFAULT

Correct Answer: (D)

[EN] When SET DEFAULT writes the default ID into the child FK, Referential Integrity still demands that default ID exist in the parent.

[HI] ON DELETE SET DEFAULT चलने पर चाइल्ड में डिफ़ॉल्ट मान भरता है, जो स्वयं पैरेंट टेबल में वैध रूप से मौजूद होना चाहिए।

Q12. Suppose Parent table Order(Order_ID) and Child table Order_Item(Order_ID, Item_No) represent a 1:N relationship. Which table holds the Foreign Key?

(यदि Order(Order_ID) और Order_Item(Order_ID, Item_No) में 1:N संबंध हो, तो फॉरेन की किस टेबल में होगी?)

(A) Order_Item (the Child / N-side table)

(B) Order (the Parent / 1-side table)

(C) Both tables reference each other in a cycle

(D) Neither table

Correct Answer: (A)

[EN] In a parent-child 1:N relation, the child (Order_Item) always holds the FK referencing the parent (Order).

[HI] 1:N संबंध में चाइल्ड या N-साइड वाली टेबल (Order_Item) ही पैरेंट (Order) को संदर्भित करने वाली फॉरेन की रखती है।

Q13. How many Foreign Keys can a single relational table contain?

(एक अकेली रिलेशनल टेबल में अधिकतम कितनी फॉरेन कीज़ (Foreign Keys) हो सकती हैं?)

(A) Strictly at most one per table, just like Primary Key

(B) At most two

(C) Zero, one, or multiple (depending on how many parent tables it relates to)

(D) Always zero in 3NF

Correct Answer: (C)

[EN] Unlike Primary Key (max 1), a table can have many Foreign Keys referencing different parent tables (for example, an Invoice referencing Customer, Staff, and Branch).

[HI] प्राइमरी की के विपरीत, एक टेबल में शून्य, एक या कई अलग-अलग फॉरेन कीज़ हो सकती हैं।

Q14. When creating two tables with a Foreign Key link (Employee referencing Department), in what order must CREATE TABLE and DROP TABLE run?

(Department को संदर्भित करने वाली Employee टेबल बनाते और हटाते समय CREATE व DROP कमांड का सही क्रम क्या होना चाहिए?)

(A) CREATE Parent (Department) first -> CREATE Child (Employee); DROP Child first -> DROP Parent

(B) CREATE Child first -> CREATE Parent

(C) Order never matters for DROP TABLE

(D) DROP Parent first -> DROP Child always succeeds

Correct Answer: (A)

[EN] A child FK cannot reference a non-existent parent, and a parent cannot be dropped while a child FK constraint still points to it.

[HI] बनाते समय पहले पैरेंट फिर चाइल्ड टेबल बनाएं; और हटाते (DROP) समय पहले चाइल्ड फिर पैरेंट टेबल हटाएं।

Q15. In SQL, what is a 'Dangling Tuple' (Orphan Record)?

(SQL डेटाबेस में 'डैंगलिंग टपल' या 'अनाथ रिकॉर्ड' (Orphan Record) का क्या अर्थ है?)

(A) A row containing NULL in a non-key column

(B) A child record containing a non-null Foreign Key value that no longer exists in the parent table

(C) A table with no indexes

(D) A parent record with zero children

Correct Answer: (B)

[EN] Orphan records occur when referential integrity is disabled or missing and a parent row is deleted while children still point to its ID.

[HI] जब चाइल्ड टेबल में किसी ऐसी पैरेंट ID का संदर्भ हो जो पैरेंट टेबल में मौजूद ही न हो, तो उसे अनाथ रिकॉर्ड या डैंगलिंग टपल कहते हैं।

Q16. Which statement about Foreign Keys is FALSE?

(फॉरेन की (Foreign Key) के विषय में निम्नलिखित में से कौन सा कथन असत्य (FALSE) है?)

(A) A Foreign Key can accept NULL values unless NOT NULL is added

(B) A Foreign Key can reference the Primary Key of the exact same table

(C) Every Foreign Key value in a child table must always be unique and never repeat

(D) A Foreign Key can reference a UNIQUE Alternate Key in the parent table

Correct Answer: (C)

[EN] Foreign Keys frequently repeat values in 1:N relationships (many orders per customer); uniqueness is NOT required on a FK unless modeling 1:1.

[HI] फॉरेन की का अद्वितीय (Unique) होना आवश्यक नहीं है; 1:N संबंध में चाइल्ड टेबल में एक ही फॉरेन की मान कई बार दोहराया जा सकता है।

Q17. Within Foreign Key: Referential Integrity Constraint and Foreign Key Rules, which referential action (parent change) directly maps to: "Rejects parent DELETE/UPDATE if children exist"?

(Foreign Key: Referential Integrity Constraint and Foreign Key Rules में कौन सा Referential Action (Parent Change) सीधे "Rejects parent DELETE/UPDATE if children exist" से संबंधित है?)

(A) RESTRICT / NO ACTION

(B) CASCADE

(C) SET NULL

(D) SET DEFAULT

Correct Answer: (A)

[EN] In Foreign Key: Referential Integrity Constraint and Foreign Key Rules, 'RESTRICT / NO ACTION' handles 'Rejects parent DELETE/UPDATE if children exist' (Default SQL behavior when no action specified).

[HI] Foreign Key: Referential Integrity Constraint and Foreign Key Rules में 'RESTRICT / NO ACTION' का कार्य/विवरण 'Rejects parent DELETE/UPDATE if children exist' (Default SQL behavior when no action specified) है।

Q18. Which option accurately describes 'CASCADE' in Foreign Key: Referential Integrity Constraint and Foreign Key Rules?

(Foreign Key: Referential Integrity Constraint and Foreign Key Rules के संदर्भ में 'CASCADE' की सही विशेषता कौन सी है?)

(A) Rejects parent DELETE/UPDATE if children exist

(B) Replaces orphaned child FK values with NULL

(C) Sets orphaned child FK to declared DEFAULT

(D) Propagates DELETE/UPDATE down to child rows

Correct Answer: (D)

[EN] 'CASCADE' provides 'Propagates DELETE/UPDATE down to child rows' — key point: Essential for Weak Entity existence dependency.

[HI] 'CASCADE' का मुख्य विवरण 'Propagates DELETE/UPDATE down to child rows' है (Essential for Weak Entity existence dependency)।

Q19. In Foreign Key: Referential Integrity Constraint and Foreign Key Rules, identify the correct parameter for the specification: "Replaces orphaned child FK values with NULL".

(Foreign Key: Referential Integrity Constraint and Foreign Key Rules में "Replaces orphaned child FK values with NULL" विवरण किस विकल्प के लिए सही है?)

(A) CASCADE

(B) SET DEFAULT

(C) RESTRICT / NO ACTION

(D) SET NULL

Correct Answer: (D)

[EN] 'SET NULL' corresponds to 'Replaces orphaned child FK values with NULL' (Fails if child FK column is declared NOT NULL).

[HI] 'SET NULL' का संबंध 'Replaces orphaned child FK values with NULL' (Fails if child FK column is declared NOT NULL) से है।

Q20. Considering Foreign Key: Referential Integrity Constraint and Foreign Key Rules, what key behavior defines 'SET DEFAULT'?

(Foreign Key: Referential Integrity Constraint and Foreign Key Rules में 'SET DEFAULT' की मुख्य भूमिका या मान क्या है?)

(A) Replaces orphaned child FK values with NULL

(B) Rejects parent DELETE/UPDATE if children exist

(C) Propagates DELETE/UPDATE down to child rows

(D) Sets orphaned child FK to declared DEFAULT

Correct Answer: (D)

[EN] 'SET DEFAULT' represents 'Sets orphaned child FK to declared DEFAULT' (Default value itself must exist in Parent PK).

[HI] 'SET DEFAULT' का अर्थ/मान 'Sets orphaned child FK to declared DEFAULT' है (Default value itself must exist in Parent PK)।

Foreign Key: Referential Integrity Constraint and Foreign Key Rules — Exam FAQs

Q1: Can a Foreign Key also be part of the child table's own Primary Key?

क्या एक फॉरेन की स्वयं चाइल्ड टेबल की प्राइमरी की का हिस्सा हो सकती है?

[EN] Yes! Very frequently—for example, in a Weak Entity table or an M:N Junction table Enrollment(Student_ID, Course_ID), both Student_ID and Course_ID are Foreign Keys AND together form the Composite Primary Key.

[HI] हाँ! अक्सर M:N जंक्शन टेबल (जैसे Enrollment(Student_ID, Course_ID)) और वीक एंटिटी टेबल में कॉलम एक साथ फॉरेन की और प्राइमरी की दोनों की भूमिका निभाते हैं।

Q2: Why should ON DELETE CASCADE be used carefully in production systems?

प्रोडक्शन सिस्टम में ON DELETE CASCADE का उपयोग सावधानी से क्यों करना चाहिए?

[EN] Because deleting a single parent row (such as one Customer or Department) silently wipes out thousands of linked historical orders or employee records across cascading child tables; often soft-deletes or RESTRICT are safer.

[HI] क्योंकि एक पैरेंट रिकॉर्ड डिलीट करने से उससे जुड़े हजारों चाइल्ड व ग्रैंड-चाइल्ड रिकॉर्ड भी चुपचाप हमेशा के लिए मिट सकते हैं; वित्तीय/ऐतिहासिक डेटा में RESTRICT सुरक्षित रहता है।

Q3: What is the difference between NO ACTION and RESTRICT in SQL?

SQL में NO ACTION और RESTRICT के बीच क्या सूक्ष्म अंतर है?

[EN] Both block parent deletion if children exist, except RESTRICT always checks immediately before executing the statement, whereas NO ACTION (in databases supporting DEFERRABLE constraints like PostgreSQL) can defer validation until the end of the transaction.

[HI] दोनों पैरेंट डिलीट को रोकते हैं; अंतर यह है कि RESTRICT तुरंत जांच करता है जबकि NO ACTION (PostgreSQL जैसे इंजन में DEFERRABLE होने पर) ट्रांजेक्शन के अंत (COMMIT) तक जांच स्थगित कर सकता है।

Related Posts

  • Loading related posts...

Post a Comment

Search Topic Notes & 20 MCQs (Hindi / English)