Integrity constraints ensure the accuracy and consistency of data in a relational database. They are rules that the database must not violate. These constraints can apply to individual attributes or to relationships between tables. They help maintain data consistency and guard against accidental damage.
Domain constraints define the valid set of values for an attribute. The domain specifies the data type and allowable values for an attribute, such as strings, characters, integers, dates, and currencies.
Similarly, a blood group attribute can only have values 'A', 'B', 'AB', or 'O'.
Entity integrity constraints ensure that the primary key of a table cannot be null because the primary key uniquely identifies each row in the table. If the primary key were null, it would be impossible to identify specific rows. While other fields in a table can contain null values, the primary key field cannot.
Referential integrity constraints enforce rules between two tables to ensure data consistency. These constraints are applied when a foreign key in one table references the primary key in another table. The rules include:
⇒ You cannot delete a record from the primary table if matching records exist in the related table.
⇒ You cannot change a primary key value in the primary table if related records exist.
⇒ You cannot insert a value in the foreign key field of the related table that does not exist in the primary key of the primary table.
⇒ You can enter a null value in the foreign key to specify that the records are unrelated.
Key constraints ensure that all values in the primary key must be unique and cannot be null. An entity set can have multiple candidate keys (minimal superkeys), but one of these keys will be chosen as the primary key. This ensures that each row in the table can be uniquely identified.