Identify the constraint type: "SALE.CNumber must exist in CUSTOMER.CNumber."

Difficulty: Easy

Correct Answer: Valid (this is a referential integrity constraint/foreign key)

Explanation:


Introduction / Context:
Understanding constraint types is essential for relational integrity. The statement "SALE.CNumber must exist in CUSTOMER.CNumber" specifies a rule connecting values across two tables. Determining the correct constraint type helps ensure correctness and efficient enforcement by the DBMS.


Given Data / Assumptions:

  • Table CUSTOMER has a column CNumber, typically declared as a primary key or at least UNIQUE/NOT NULL.
  • Table SALE has a column CNumber that references CUSTOMER.CNumber.
  • We are discussing declarative constraints supported by the DBMS.


Concept / Approach:
A referential integrity constraint (foreign key) ensures that each non-null value in a referencing column (SALE.CNumber) matches an existing value in the referenced column (CUSTOMER.CNumber). This preserves parent–child relationships and prevents orphan records. The DBMS enforces the rule on INSERT/UPDATE and, with defined actions, on DELETE/UPDATE in the parent.


Step-by-Step Solution:

Declare CUSTOMER.CNumber as a primary or unique key.Declare a foreign key on SALE(CNumber) referencing CUSTOMER(CNumber).Optionally specify ON DELETE/UPDATE actions (RESTRICT, CASCADE, SET NULL/DEFAULT).Verify that inserts into SALE require a matching CUSTOMER row.


Verification / Alternative check:
Attempt to insert SALE(CNumber) = 999 when no CUSTOMER row has CNumber = 999; the DBMS should reject the statement due to the foreign key violation.


Why Other Options Are Wrong:

  • Check constraints validate conditions within one row; they cannot consult another table’s values.
  • Unique constraints apply to one table only and do not enforce cross-table existence.
  • Triggers can enforce such rules, but this rule is expressible and best handled as a built-in foreign key constraint.


Common Pitfalls:
Forgetting to index the referencing column for performance; neglecting ON DELETE/UPDATE actions that match business rules; using triggers instead of declarative constraints unnecessarily.


Final Answer:
Valid (this is a referential integrity constraint/foreign key)

More Questions from Database Design Using Normalization

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion