This set of MySQL Database Multiple Choice Questions & Answers (MCQs) focuses on “Foreign Keys and Referential Integrity”.
1. Which key declares that an index in one table is related to that in another?
Explanation: In MySQL, a foreign key is the one which facilitates index relations across tables. It declares that an index in one table is related to that in another and place constraints.
2. Foreign keys cannot handle deletes and updates.
Explanation: A foreign key is the one which declares that an index in one table is related to that in another and place constraints. It is useful for handling deletes and updates along with row entries.
3. Deletion of an employee from table also deletes that employee from another table. This kind of delete is called ____________
Explanation: In MySQL, a cascaded delete and update is possible where records can be deleted from multiple tables. These tables are related with the help of foreign keys. Foreign keys make table updates flexible.
4. Which storage engine in MySQL provides foreign key support?
Explanation: In MySQL, there are a list of storage engines to choose from. Each storage engine provides its own set of facilities. The foreign key facilities are provided by the InnoDB storage engine.
5. The property of InnoDB that enforces foreign key relationships stay intact is called _____________
d) referential integrity
Explanation: The storage engine responsible for providing foreign key support is InnoDB. It enforces that the rules guarantee the foreign key relationship stays intact with no mismatching of data.
6. Which clause names the parent table and the index columns in the table?
b) ON DELETE
d) FOREIGN KEY
Explanation: In MySQL foreign key definition syntax, there are various components, namely, FOREIGN KEY, CONSTRAINT, REFERENCES and ON DELETE. The REFERENCES clause names the parent table and the index columns in the table.
7. If the storage engine InnoDB is not used, foreign key cannot be used.
Explanation: The foreign key support is exclusively provided by the storage engine named InnoDB. Without its inclusion, foreign keys cannot be used. However it is possible to implement with application logic.
8. Which clause is used to remove a foreign key constraint?
Explanation: In MySQL foreign key definition syntax, there are various components. A foreign key links one table to another table in the table. To remove a foreign key constraint, the ‘DROP’ clause is used.
9. Which keyword is used to specify the foreign key after the table is created?
c) ALTER TABLE
Explanation: When the table has already been created but the foreign key has not been set of foreign key constraints are not specified, the ‘ALTER TABLE – ADD FOREIGN KEY’ clause is used.
10. Which clause in the SQL standard controls how NULL values in a composite foreign key are handled when comparing to a primary key.
c) ON DELETE
d) ON CASCADE
Explanation: The MATCH clause in the SQL standard controls how NULL values in a composite (multiple-column) foreign key are handled when comparing to a primary key. MySQL essentially implements the semantics defined by MATCH SIMPLE.
Sanfoundry Global Education & Learning Series – MySQL Database.
To practice all areas of MySQL Database, here is complete set of 1000+ Multiple Choice Questions and Answers.
If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]