In standard SQL, which constraint type is used directly on a column or table to limit allowed values (for example, enforce a range, a list, or a comparison rule)?
-
ALIMIT constraint
-
BCHECK constraint
-
CVALUE constraint
-
DNone of the above
-
EFILTER constraint
Answer
Correct Answer: CHECK constraint
Explanation
Introduction / Context:To keep data valid at the source, SQL provides declarative constraints that the database enforces automatically. Choosing the right constraint ensures data integrity without application-side duplication.
Given Data / Assumptions:
- We want to restrict a column's allowed values (e.g., 1–100, set membership, or column relationships).
- The constraint should be enforced on every INSERT and UPDATE.
- We prefer a portable, standard mechanism.
Concept / Approach:The CHECK constraint evaluates a Boolean expression per row. If the expression evaluates to true, the row is allowed; otherwise the statement fails. CHECK can reference one or more columns of the same row and supports ranges, sets, and simple predicates.
Step-by-Step Solution:
Define desired rule as a Boolean expression.Attach it as a CHECK constraint to the column or table.Database enforces the rule for all DML operations.Verification / Alternative check:Attempt to insert an invalid value; the database rejects it with a CHECK violation, proving the constraint works.
Why Other Options Are Wrong:LIMIT / VALUE / FILTER constraint: Not standard SQL constraint names. None of the above: Incorrect because CHECK is the standard mechanism.
Common Pitfalls:Writing overly complex CHECK expressions can hurt readability; keep them clear and document business rules.
Final Answer:CHECK constraint