Alter Table To Remove Foreign Key Or Add DELETE CASCADE (MySQL)
Maybe your like
- Laravel
- Learn Laravel
- Livewire Tutorials
- Laravel Dusk
- Frontend
- TailwindCSS
- Bootstrap
- AlpineJS
- Components
- Livewire Components
- TailwindCSS Components
- Courses
- Laravel Dusk
- AlpineJS
- About
- About Me
- My Stack
- Advertise
- Laravel
- Learn Laravel
- Livewire Tutorials
- Laravel Dusk
- Frontend
- TailwindCSS
- Bootstrap
- AlpineJS
- Components
- Livewire Components
- TailwindCSS Components
- Courses
- Laravel Dusk
- AlpineJS
- About
- About Me
- My Stack
- Advertise
SQL
Alter table to remove Foreign Key or add DELETE CASCADE (MySQL) SQLtgugnani
Dec 20, 2016
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=utf8
Step 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 later
Step 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

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