Which SQL statement correctly alters table STUDENT to add a named CHECK constraint GradeCheck requiring that Grade values be greater than 0 (strictly positive)?

Difficulty: Easy

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

ADD CONSTRAINT CHECK (). The predicate uses normal boolean logic; here it is Grade > 0. The verb “ALTER CONSTRAINT” is typically used to modify properties of an existing constraint, not to define the check expression from scratch.



Step-by-Step Solution:

1) Choose ALTER TABLE to modify structure and constraints of an existing table.2) Use ADD CONSTRAINT to create a new, named constraint.3) Specify CHECK (Grade > 0) as the rule.


Verification / Alternative check:

Run a small test: insert a row with Grade = 0 or Grade = -1 and confirm the database rejects it with a constraint violation; insert Grade = 1 and confirm success.



Why Other Options Are Wrong:

Option A: ALTER CONSTRAINT requires an existing constraint; syntax omits CHECK keyword.

Option B: Missing the CHECK keyword; incomplete definition.

Option D: Incorrect because Option C is valid.



Common Pitfalls:

Forgetting to name the constraint, which complicates later maintenance; writing Grade >= 0 by mistake if the business rule requires strictly positive values.



Final Answer:

ALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);

Discussion & Comments

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