Question

Given the following statements:

S1: A foreign key declaration can always be replaced by an equivalent check assertion in SQL.

S2: Given the table R(a,b,c) where a and b together form the primary key, the following is a valid table definition.

CREATE TABLE S (
  a INTEGER,
  d INTEGER,
  e INTEGER,
  PRIMARY KEY (d),
  FOREIGN KEY (a) references R
)

Which one of the following statements is CORRECT?

Choose one option
Official answer and solution
Official answer
D
From
Official GATE 2014 answer key

Solution

Analyze SQL constraints and foreign key syntax rules.

Evaluate each statement:

  1. Statement S1: 'A foreign key declaration can always be replaced by an equivalent check assertion in SQL.'

    • A foreign key not only enforces referential integrity on insert/update of the child table, but also dictates cascade actions (e.g., ON DELETE CASCADE, ON UPDATE SET NULL) when the referenced row in the parent table is deleted or modified. Standard check constraints/assertions cannot replicate these automated referential update behaviors.
    • Hence S1 is FALSE.
  2. Statement S2: 'Given the table R(a,b,c) where a and b together form the primary key, the following is a valid table definition: ... FOREIGN KEY (a) references R'

    • In SQL standard and relational database design, a foreign key must reference a candidate key (primary key or unique constraint) of the referenced table.
    • In table RR, the primary key is composite: (a,b)(a, b). A foreign key referencing only attribute aa does not reference a candidate key of RR, which is an error and violates SQL semantics.
    • Hence S2 is FALSE.

Both S1 and S2 are FALSE.

Final answer

D

Common trap

Thinking a foreign key can reference any individual attribute belonging to a composite primary key.

The answer is the one in the official GATE answer key. The solution is this site's own explanation.

Source

Paper
GATE 2014 Computer Science and Information Technology (CS) Session 1
Question
32 of 65, printed as CS Q.22
Section
Computer Science and Information Technology

Report an error in this question

GATE questions are the work of the organising institutes. This site is independent and is not affiliated with them.