InnoDB mySQL unable to set "ON DELETE SET DEFAULT'. How to set?

前端 未结 3 1610
长发绾君心
长发绾君心 2021-01-18 19:24

I am trying to create a table named EMPLOYEE. When I use the following statements without \"ON DELETE SET DEFAULT\" it is working.

Here is the Error I get with \"ON

3条回答
  •  失恋的感觉
    2021-01-18 20:02

    You can't use ON DELETE SET DEFAULT or ON UPDATE SET DEFAULT with InnoDB

    InnoDB and FOREIGN KEY Constraints
    While SET DEFAULT is allowed by the MySQL Server, it is rejected as invalid by InnoDB. CREATE TABLE and ALTER TABLE statements using this clause are not allowed for InnoDB tables.

    You may try ON DELETE SET NULL if it fits your needs

    If ON UPDATE CASCADE or ON UPDATE SET NULL recurses to update the same table it has previously updated during the cascade, it acts like RESTRICT. This means that you cannot use self-referential ON UPDATE CASCADE or ON UPDATE SET NULL operations. This is to prevent infinite loops resulting from cascaded updates. A self-referential ON DELETE SET NULL, on the other hand, is possible, as is a self-referential ON DELETE CASCADE. Cascading operations may not be nested more than 15 levels deep

    Here is SQLFiddle demo

提交回复
热议问题