3 ms·
If you put your constraints in the database schema, then you check for errors on insert/update/etc., like you said, with try-catch. If you put your constraints
by lost-theory 15y ago
If you put your constraints in the database schema, then you check for errors on insert/update/etc., like you said, with try-catch.
If you put your constraints in the application code, you usually have some validation layer that the data passes through before sending it to the DB.
It's common to have validation live both in the DB and in the app code. The constraints in the app code are for catching and displaying errors up front and display them to the user (e.g. on a form), while the DB constraints are used as a last line of defense to ensure data integrity.