Constraints

Primary key

A primary key is a column or a group of columns used to uniquely identify a row in a table. Technically, it is a combination of the NULL constraint and the UNIQUE constraint. In case the primary key consists of two or more columns, the primary key constraint is defined as follows. If no name Primary key

Foreign Key

A foreign key is a column or group of columns in a table that references the primary key constraint of another table. The foreign key constraint preserves the referential integrity of the data between the child and parent tables. The foreign key constraint indicates that values in a column or group of columns in the Foreign Key

Check Constraint

The CHECK constraint is a type of constraint that makes sure the values in a column meet a certain requirement. If the values qualify the CHECK constraint, PostgreSQL adds or updates these values to the column. Otherwise, PostgreSQL will reject the changes and throw a constraint violation error. The last query returns an error because Check Constraint

Unique Constraints

When the UNIQUE constraint is applied, every time you add a new row it checks if the value is already in the table. If the value exists in the column, it rejects the change and returns an error. The same process is performed for updating existing data. Example: The command adds a unique constraint to Unique Constraints

Not-Null Constraint

In database theory, NULL represents unknown or missing information. NULL is not the same as an empty string or number of zeros. Courtesy to this constraint, any row in the column to which this constraint is added cannot be left blank. A value must be entered. To add NOT NULL constraint to the existing column;