I need to temporarily disable all constraints and triggers of a schema in order to anonymize data in several tables. As there are dependencies between tables, I prefer to disable everything and once the anonymization treatment is over I can enable all constraints and triggers one more time.
I tried SET FOREIGN_KEY_CHECKS=0;
and I got this error:
ERROR: unrecognized configuration parameter "foreign_key_checks"
SQL state: 42704
I’ve been reading a lot about that and some people say this is not possible.
Do you know a way to do that?
Thank you!
2
Answers
I found this solution,
I created a temporal table to keep all constraints definition:
Then I drop all constraints:
And after anonymizing data I restore all constraints using the definitions in the temporal table and I drop the temporal table:
I hope this can help someone else. Thank you!
To disable foreign keys and deferrable unique and primary key constraints for a table, you can use
To disable all such constraints for the duration of a database session, you can
Both tricks won’t work for non-deferrable constraints and check constraints.