You need to ensure, within a single row of the same table, that the value in one column is always less than the value in another column (for example, start_amount < end_amount). Which type of data constraint best enforces this rule?
-
AA domain constraint
-
BA range constraint
-
CAn intrarelation constraint
-
DAn interrelation constraint
-
EA foreign key constraint
Answer
Correct Answer: An intrarelation constraint
Explanation
Introduction / Context:Business rules often compare two columns in the same row, such as start_date before end_date or minimum_value less than maximum_value. Enforcing this rule in the database ensures integrity regardless of application code and prevents bad data from being stored.
Given Data / Assumptions:
- The comparison is row-internal: ColumnA of a row must be less than ColumnB of the same row.
- We are working within a single table; no cross-table relationship is required.
- We want the DBMS to reject any row violating the rule.
Concept / Approach:An intrarelation constraint (often implemented as a CHECK constraint) enforces relationships among columns within the same table row. For example: CHECK (start_amount < end_amount). In contrast, interrelation constraints involve two tables (such as foreign keys). Domain or range constraints restrict individual columns independently without referencing other columns.
Step-by-Step Solution:
Identify the rule: ColumnA must be less than ColumnB in the same row.Implement a CHECK constraint on the table: CHECK (ColumnA < ColumnB).Test by inserting valid and invalid rows to confirm enforcement.Verification / Alternative check:Attempt to insert a row with ColumnA >= ColumnB. The DBMS should raise an error, demonstrating that the intrarelation constraint works as intended.
Why Other Options Are Wrong:
- Domain/range constraints: Apply to a single column's allowable values without comparing to another column.
- Interrelation constraint: Involves multiple tables, not needed here.
- Foreign key constraint: Ensures referential integrity across tables, not comparisons within one row.
Common Pitfalls:For nullable columns, specify the intended behavior (for example, require NOT NULL or include logic such as CHECK (ColumnA IS NULL OR ColumnB IS NULL OR ColumnA < ColumnB)).
Final Answer:An intrarelation constraint