PostgreSQL Constraints: Learning PostgreSQL with Grant


 

PostgreSQL supports constraints much like any other database management system. When you need to ensure certain behaviors of the data, you can put these constraints to work. I’ve already used several of these in creating my sample database (available articles publicly on GitHub, in the CreateDatabase.sql file). I’ll explain those as we go. The constraints supported by PostgreSQL are:

Not-Null Constraints Unique Constraints Primary Key Foreign Key Check Constraints Exclusion Constraints Not-Null Constraints

One way we can ensure that our data is correct is by requiring it in the first place. If you create a table like this: