Sql - Constraints
Code Life
By Pierre Marsaa
Rules the database enforces
A constraint is a rule attached to a column. The database checks it on every INSERT and UPDATE, and refuses anything that breaks it. NOT NULL requires a value; UNIQUE forbids two rows with the same value:
↗️
Loading editor...
↶
↷
Now try to register Tide Gym a second time:
↗️
Loading editor...
↶
↷
Why bother?
You could check these rules in your application instead. But applications have bugs, and several applications may write to the same database. A constraint is checked every time, by everyone, with no exception.
Verify