patternsqlMinor
Is it possible to check all constraints in a MySQL database?
Viewed 0 times
constraintsalldatabasepossiblemysqlcheck
Problem
MySQL offers the ability to temporarily disable the foreign key checks, thus allowing inconsistent data to enter the database.
Is it possible to check an entire MySQL database, table by table, row by row, to ensure that all constraints are satisfied?
Is it possible to check an entire MySQL database, table by table, row by row, to ensure that all constraints are satisfied?
Solution
Long ago I wrote a tool called oak-apply-ri. It is part of the openark-kit, which is generally well accepted. I'm beginning with the disclaimer that this tool is less popular, and I don't have much input about it (other than my own).
Nevertheless, it allows you to specify two tables that share a FK relationship, and it will verify whether the constraint holds.
You can ask it to actually resolve the differences via
If you are suspicious, you may ask it to
I'm happy to get any feedback on this.
Nevertheless, it allows you to specify two tables that share a FK relationship, and it will verify whether the constraint holds.
You can ask it to actually resolve the differences via
--action=delete or --action=setnull. If you are suspicious, you may ask it to
--print-only in which case it will not apply any changes to your database; instead it will print out the statements it would like to invoke on the database.I'm happy to get any feedback on this.
Context
StackExchange Database Administrators Q#33213, answer score: 2
Revisions (0)
No revisions yet.