Question
Computer Science Question on SQL
Which of the following is correct syntax for inserting foreign key constraint in a relation?
A
ALTER TABLE table_name ADD FOREIGN KEY(attribute_name) REFERENCES referenced_table_name(attribute_name)
B
ADD TABLE table_name ADD FOREIGN KEY(attribute_name) REFERENCES referenced_table_name(attribute_name)
C
ALTER TABLE table_name REFERENCES referenced_table_name(attribute_name) ADD FOREIGN KEY(attribute_name)
D
MODIFY TABLE table_name ADD FOREIGN KEY(attribute_name) REFERENCES referenced_table_name(attribute_name)
Answer
ALTER TABLE table_name ADD FOREIGN KEY(attribute_name) REFERENCES referenced_table_name(attribute_name)
Explanation
Solution
The correct syntax for adding a foreign key constraint is through ALTER TABLE, adding a FOREIGN KEY and referencing another table.