Alter Table To Remove Foreign Key Or Add DELETE CASCADE (MySQL)
Maybe your like
5Balloons Tech Home Projects Blog Personal About Home Projects Blog Personal About
T
Step 1 : Get the Foreign Key Name.
SHOW CREATE TABLE tableName; Note the name of Foreign key (which is mostly auto generated) output will look something like CONSTRAINT `FK4C5B93445F11A0B7` FOREIGN KEY (ID`) REFERENCES `PARENT_TABLE` (`ID`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8Step 2: Drop the Foreign Key.
Alter table tableName drop foreign key FK4C5B93445F11A0B7 Dont worry, this will not harm your data. It will just remove the constraint. You can add it back laterStep 3: Now add the foreign key constraint back again, this time with ON DELETE CASCADE
alter table tableName add foreign key (ID) references PARENT_TABLE(ID) on DELETE CASCADE There you Go! You can run SHOW CREATE TABLE tableName; to verify on DELETE CASCADE
T Written by Tushar
Related Posts
SQLImport mysql dump to RDS Db Instance
Mar 11, 2016 →Tag » Add Constraint On Delete Cascade Mysql
-
How To Add 'ON DELETE CASCADE' In ALTER TABLE Statement
-
MySQL 8.0 Reference Manual :: 13.1.20.5 FOREIGN KEY Constraints
-
MySQL ON DELETE CASCADE - Javatpoint
-
MySQL ON DELETE CASCADE: Deleting Data From Related Tables ...
-
MySQL - ON DELETE CASCADE Constraint - GeeksforGeeks
-
Mysql Alter Table Add Constraint Foreign Key On Delete Cascade Code ...
-
DELETE CASCADE And UPDATE CASCADE In SQL Server Foreign ...
-
SQL Server: Foreign Keys With Cascade Delete - TechOnTheNet
-
MySQL DELETE CASCADE - Linux Hint
-
[Résolu] Sql | Comment Ajouter 'ON DELETE CASCADE' Dans
-
13.1.17.5 FOREIGN KEY Constraints - Oracle Help Center
-
Add ON DELETE CASCADE To Foreign Key Constraint
-
Using The ON DELETE CASCADE Option - IBM
-
MySQL ON DELETE CASCADE - StackHowTo