Constraints are a part of the table definition that limits the values inserted into its columns.
Which type of data a table can store that may be decided by the type of data. That is why CONSTRAINTS needed. Suppose the age of a student is always be a positive value but there is no such data type which can accept the only positive value, a CONSTRAINT can do this.
|NOT NULL||The not-null constraint in PostgreSQL ensure that a column can not contain any null value. This is a column constraint. No name can be defined to create a not-null constraint.|
|UNIQUE||The unique constraint in PostgreSQL ensure that the value entered into a column or a field of a table is unique.|
|CHECK||The check constraint in PostgreSQL is used to specify that the value in a specific column or field of a table must match a boolean expression. This constraint can be defined as a separate name.|
|PRIMARY KEY||This the requirement of an efficient database to ensure that there are no duplicate records within a single table. A field whose value uniquely identifies a record in a table is called a primary key.|
|FOREIGN KEY||The unique constraint in PostgreSQL specifies that the valued in a field or a column of a table must match to the actual value of the primary key of another table.|
Solve these problems: