Ask the Expert

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!

    Requires Free Membership to View

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

There are Comments. Add yours.

 
TIP: Want to include a code block in your comment? Use <pre> or <code> tags around the desired text. Ex: <code>insert code</code>

REGISTER or login:

Forgot Password?
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
Sort by: OldestNewest

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: