Which keyword is used to specify the foreign key after the table is created?
A. SETUP
B. SET
C. ALTER TABLE
D. SPECIFY
Answer: Option C
Solution (By Examveda Team)
This question is about how to add a foreign key to a table in MySQL after the table has already been created.A foreign key is a column in one table that refers to the primary key of another table. This helps maintain data integrity by ensuring that the related data in both tables is consistent.
The correct answer is Option C: ALTER TABLE. Here's why:
* ALTER TABLE is the command used to modify the structure of an existing table. * SET is used to assign values to variables. * SETUP is not a standard MySQL keyword. * SPECIFY is not used for this purpose in MySQL.
To add a foreign key to a table using ALTER TABLE, you would use a syntax like this:
ALTER TABLE table_name ADD CONSTRAINT constraint_name FOREIGN KEY (column_name) REFERENCES other_table_name (other_column_name);
Example:
ALTER TABLE orders ADD CONSTRAINT fk_customer FOREIGN KEY (customer_id) REFERENCES customers (customer_id);
This would create a foreign key constraint named `fk_customer` on the `orders` table, ensuring that the `customer_id` in the `orders` table matches a valid `customer_id` in the `customers` table.
Related Questions on MySQL Miscellaneous
How is communication established with MySQL?
A. SQL
B. Network calls
C. A programming language like C++
D. APIs
Which type of database management system is MySQL?
A. Object-oriented
B. Hierarchical
C. Relational
D. Network

Join The Discussion