Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

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?

share|improve this question
    
I actually wrote a tool to do this here: github.com/moorej/fkchk –  josten Apr 30 '13 at 4:26
    
@JMoore interesting, I'll have a look, thanks! –  Benjamin Apr 30 '13 at 10:50
add comment

1 Answer

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 --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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.