Constraints specify rules for data in a SQL database. They ensure that data in a database remains valid. Some common constraints for RDBMSs include:

  • Not Null: Prevents storing a NULL value in a column.
  • Unique: Prevents a duplicate value of, for example, a primary key.
  • Primary Key: A combination of a NOT NULL and UNIQUE. Ensures that a key field contains a unique value.
  • Foreign Key: Ensures there is an actual value in the referenced table; one that cannot be deleted.
  • Check Constraint: Allows only specific values in a field.
  • Default: Sets a default value for a field.