You need to modify the STUDENTS table to add a primary key on the STUDENT_ID column. The table is currently empty. Which statement accomplishes this task?
-
ALTER TABLE students ADD PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id);
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id;
-
ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
-
ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
The correct SQL syntax for adding a primary key constraint to an existing table is ALTER TABLE table_name ADD CONSTRAINT constraint_name PRIMARY KEY (column_name). Parentheses are required around the column list, and MODIFY is not used for adding constraints.
To add a primary key on the STUDENT_ID column in the STUDENTS table, you can use the following statement:
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id);
Explanation for each option:
A. ALTER TABLE students ADD PRIMARY KEY student_id; This option is incorrect because it is missing the CONSTRAINT keyword before PRIMARY KEY.
B. ALTER TABLE students ADD CONSTRAINT PRIMARY KEY (student_id); This option is incorrect because it is missing a name for the constraint. A constraint must have a unique name.
C. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY student_id; This option is incorrect because it is missing parentheses around the column name student_id.
D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is correct because it uses the correct syntax to add a constraint with a name (stud_id_pk) on the column student_id as the primary key.
E. ALTER TABLE students MODIFY CONSTRAINT stud_id_pk PRIMARY KEY (student_id); This option is incorrect because MODIFY CONSTRAINT is used to modify an existing constraint, not to add a new constraint.
The correct answer is D. ALTER TABLE students ADD CONSTRAINT stud_id_pk PRIMARY KEY (student_id). This option is correct because it adds a primary key constraint with the name stud_id_pk on the column student_id in the STUDENTS table.