Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable vs. Drop Constraint

What is the functional difference between those two opetions?

When inserting data on a large table I personally would disable the constraint. But does it make any difference to the drop constraint? I am disabling the constraint because otherwise inserts are pretty slow.

like image 515
user2428207 Avatar asked Feb 13 '26 10:02

user2428207


1 Answers

If you're doing data loads or other maintenance, it makes sense to disable rather than drop a constraint.

The idea is, if you know you're going to want to get that constraint back when you're done w/ the data load or maintenance, then disable it. When you're done, you can simply enable it.

You shouldn't drop, unless you're reasonably certain you won't need that constraint in the future. The danger of dropping rather than disabling is that you may get it slightly (or completely) wrong when you re-create the constraint. If you simply disable, there's no danger of losing the constraint definition, as the constraint definition remains in the data dictionary.

like image 125
Mark J. Bobak Avatar answered Feb 16 '26 03:02

Mark J. Bobak



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!