Difficulty: Easy
Correct Answer: ALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);
Explanation:
Introduction / Context:
This question tests understanding of how to add a CHECK constraint to an existing table in SQL. A CHECK constraint enforces a condition that must be true for all rows in the table. In this case, the requirement is that the Grade column must always contain values greater than zero. The syntax for adding such a constraint using ALTER TABLE is important for database integrity and exam questions related to SQL Data Definition Language.
Given Data / Assumptions:
Concept / Approach:
In standard SQL, adding a check constraint to an existing table is done via ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK condition. The condition in this case is Grade > 0. The CHECK keyword is mandatory to indicate the type of constraint. Statements that omit CHECK or use incorrect verbs such as ALTER CONSTRAINT or MODIFY for creating a new constraint will not be valid for this purpose. Therefore, the correct answer must include both ADD CONSTRAINT and CHECK with the proper condition.
Step-by-Step Solution:
Step 1: Recall the general syntax for adding a check constraint: ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (condition).Step 2: Substitute the table name STUDENT, the constraint name GradeCheck, and the condition Grade > 0 into this syntax.Step 3: Form the complete statement: ALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);Step 4: Compare this statement with the options provided in the question.Step 5: Confirm that the option that exactly matches this syntax is the correct one.
Verification / Alternative check:
Consulting SQL documentation or examples, the pattern ALTER TABLE table_name ADD CONSTRAINT constraint_name CHECK (condition) is consistently shown as the proper way to add a check constraint. Variants that omit the CHECK keyword or misuse ALTER CONSTRAINT are reserved for modifying existing constraints, not creating new ones. Since GradeCheck is being added rather than changed, the ADD CONSTRAINT syntax is required. This confirms that the option using ADD CONSTRAINT with CHECK is correct.
Why Other Options Are Wrong:
The option using ALTER CONSTRAINT GradeCheck (Grade > 0) is incorrect because ALTER CONSTRAINT is typically used to modify existing constraints, and the syntax shown is not valid for creating a new check constraint. The option that uses ADD CONSTRAINT GradeCheck (Grade > 0) but omits the CHECK keyword is incomplete and not valid SQL. The statement that none of the options is correct is wrong because a valid statement is present. The option with MODIFY GradeCheck AS (Grade > 0) is not standard SQL syntax for adding a check constraint and is therefore incorrect.
Common Pitfalls:
Students often forget the CHECK keyword or confuse ADD CONSTRAINT with MODIFY or ALTER syntax designed for other purposes. Another pitfall is mixing Data Definition Language with Data Manipulation Language syntax. To avoid such errors, always memorize the basic pattern for adding constraints and practice writing it with different conditions. Knowing the structure makes it easier to identify the correct answer in multiple choice questions.
Final Answer:
The correct SQL command is ALTER TABLE STUDENT ADD CONSTRAINT GradeCheck CHECK (Grade > 0);
Discussion & Comments