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

Join the conversationComment

Share
Comments

    Results

    Contribute to the conversation

    All fields are required. Comments will appear at the bottom of the article.