TLDR: Is there a script or SQL query to mimic the functionality “Disable the related foreign keys”
I am working on a project which uses multiple tables and some tables have multiple foreign keys too. I need to truncate the tables often and for disabling the related foreign keys I need to use the options every time which is a tedious process. Is there an SQL query equivalent for that I can run it any time I want?
Advertisement
Answer
If you are doing it frequently, then create a script which will
- disable foreign key constraints
- truncate tables
- enable constraints
so you’d just run a script and watch it doing the job.
Or, if tables contain not-that-many-rows, delete them (instead of truncating tables); then you won’t have that problem.