MySQL Questions and Answers – Foreign Keys and Referential Integrity

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?
a) primary
b) secondary
c) foreign
d) cross
View Answer

Answer: c
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.
a) True
b) False
View Answer

Answer: b
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 ____________
a) transparent
b) concrete
c) elaborate
d) cascaded
View Answer

Answer: d
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.
advertisement
advertisement

4. Which storage engine in MySQL provides foreign key support?
a) TRANSACTION
b) InnoDB
c) MyISAM
d) MEMORY
View Answer

Answer: b
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 _____________
a) atomicity
b) durability
c) consistency
d) referential integrity
View Answer

Answer: d
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?
a) REFERENCES
b) ON DELETE
c) CONSTRAINT
d) FOREIGN KEY
View Answer

Answer: a
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.
a) True
b) False
View Answer

Answer: a
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.
advertisement

8. Which clause is used to remove a foreign key constraint?
a) REMOVE
b) DELETE
c) DROP
d) EXCLUDE
View Answer

Answer: c
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?
a) SETUP
b) SET
c) ALTER TABLE
d) SPECIFY
View Answer

Answer: c
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.
advertisement

10. Which clause in the SQL standard controls how NULL values in a composite foreign key are handled when comparing to a primary key.
a) SET
b) MATCH
c) ON DELETE
d) ON CASCADE
View Answer

Answer: b
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.

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.