I�m trying to run some batch commands one after the other - Yet since part of them may fail due to constraints failures � I want to turn off the DB constraints, and turn it back on just after the last batch is executed (in the same connection!!!). Once the constraints are back � I want to see all the constraints failure. (apparently � there�ll be none)
How can I turn the DB constraints off at the beginning of the batch execution, And later turn it on and see the result and errors?
Sharon, Some databases (like Oracle) store the constraints in a table. In those databases, disabling/enabling constraints can be done through SQL. I'm not sure how mySQL does it, but you might want to have a look if there are system tables.
I've tried Remko suggestion, and wrote this simple main:
Surprisingly, executing "SET FOREIGN_KEY_CHECKS=1" succeeded, in spite of the illegal my_second_class_id 'pizza'! Those changes were written to the DB, and showed no errors or constraint failures! I didn't expect this. I hoped once the constraints are turned on, all the rows will be checked, and a sqlException with constraint failure will be thrown. How can I see those errors once the constraints are back?