2

I have been working on MySQL for the past few months. Kindly apologize if my question is silly.

We have Foreign key Checks,

Enable - SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,FOREIGN_KEY_CHECKS=1;

Disable - SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS,FOREIGN_KEY_CHECKS=0;

Similarly,

Do we have any Query to Enable and Disable ON DELETE CASCADE in MySQL?

Thanks.

Vimal Raj
  • 23
  • 4
  • possible duplicate of [How do I use cascade delete with SQL Server?](http://stackoverflow.com/questions/6260688/how-do-i-use-cascade-delete-with-sql-server) – Nikhil Talreja Jun 26 '14 at 07:03

2 Answers2

0

You will need to

drop the existing foreign key constraint add a new one with the ON DELETE CASCADE setting enabled

Nikhil Talreja
  • 2,754
  • 1
  • 14
  • 20
0

Create new foreign key constraint using :

CREATE TABLE table_name
(
  column1 datatype null/not null,
  column2 datatype null/not null,
  ...

  CONSTRAINT fk_column
     FOREIGN KEY (column1, column2, ... column_n)
     REFERENCES parent_table (column1, column2, ... column_n)
     ON DELETE CASCADE
);

or alter the existing constraint:

ALTER TABLE table_name
ADD CONSTRAINT constraint_name
   FOREIGN KEY (column1, column2, ... column_n)
   REFERENCES parent_table (column1, column2, ... column_n)
   ON DELETE CASCADE;
SparkOn
  • 8,806
  • 4
  • 29
  • 34