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 first 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.

0 comments

Oldest 

Forgot Password?

No problem! Submit your e-mail address below. We'll send you an email containing your password.

Your password has been sent to:

-ADS BY GOOGLE

SearchDataCenter

SearchServerVirtualization

SearchCloudComputing

SearchEnterpriseDesktop

Close