Q

Cascade with foreign keys

You said that MySQL supports foreign keys, but I would like to know if it is possible to cascade updates and deletes using foreign key constraints. If it is possible to do so in another way, please instruct. Thank you!

If you take a look at http://dev.mysql.com/doc/mysql/en/InnoDB_foreign_key_constraints.html you will see that the following FOREIGN KEY constraints are supported when using InnoDB:

[CONSTRAINT symbol] FOREIGN KEY [id] (index_col_name, ...)
    REFERENCES tbl_name (index_col_name, ...)
    [ON DELETE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]
    [ON UPDATE {RESTRICT | CASCADE | SET NULL | NO ACTION | SET DEFAULT}]
As you can see, CASCADE is one of the supported actions for UPDATE and DELETE statements.


This was last published in August 2004

Dig Deeper on Open source databases

Have a question for an expert?

Please add a title for your question

Get answers from a TechTarget expert on whatever's puzzling you.

You will be able to add details on the next page.

Start the conversation

Send me notifications when other members comment.

By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Please create a username to comment.

-ADS BY GOOGLE

SearchDataCenter

SearchServerVirtualization

SearchCloudComputing

SearchEnterpriseDesktop

Close