Which SQL statement correctly alters table STUDENT to add a named CHECK constraint GradeCheck requiring that Grade values be greater than 0 (strictly positive)?
-
AALTER TABLE STUDENT ALTER CONSTRAINT GradeCheck (Grade > 0);
-
BALTER TABLE STUDENT ADD CONSTRAINT GradeCheck (Grade > 0);
-
CALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);
-
DNone of the above is correct.
Answer
Correct Answer: ALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);
Explanation
Introduction / Context:CHECK constraints enforce row-level data rules directly in the database. Adding a named constraint improves maintainability and allows targeted enable/disable and error messages. The task is to identify the correct SQL syntax for adding such a constraint.
Given Data / Assumptions:
- Table name: STUDENT.
- Constraint name: GradeCheck.
- Rule: Grade must be greater than 0.
Concept / Approach:
Most SQL dialects support the pattern: ALTER TABLE