Integrity Constraints
Integrity Constraints
In database management systems (DBMS) there is a certain set of rules which are
used to maintain the quality and consistency of data in the database. Every time
there is an insertion, deletion, or updating of data in the database it is the
responsibility of these integrity constraints to maintain the integrity of data and
thus help to prevent accidental damage to the database.
What are Integrity Constraints in DBMS?
In Database Management Systems, integrity constraints are pre-defined set of rules that are
applied on the table fields(columns) or relations to ensure that the overall validity, integrity,
and consistency of the data present in the database table is maintained. Evaluation of all the
conditions or rules mentioned in the integrity constraint is done every time a table insert,
update, delete, or alter operation is performed. The data can be inserted, updated, deleted,
or altered only if the result of the constraint comes out to be True. Thus, integrity
constraints are useful in preventing any accidental damage to the database by an authorized
user.
Domain Constraint
Domain integrity constraint contains a certain set of rules or conditions to restrict the kind of
attributes or values a column can hold in the database table. The data type of a domain can
be string, integer, character, DateTime, currency, etc.
Entity Integrity Constraint is used to ensure that the primary key cannot be null. A primary
key is used to identify individual records in a table and if the primary key has a null value,
then we can't identify those records. There can be null values anywhere in the table except
the primary key column.
Referential Integrity Constraint ensures that there must always exist a valid relationship
between two relational database tables. This valid relationship between the two tables
confirms that a foreign key exists in a table. It should always reference a corresponding value
or attribute in the other table or be null.
Key constraint
Keys are the set of entities that are used to identify an entity within its entity set uniquely.
There could be multiple keys in a single entity set, but out of these multiple keys, only one key
will be the primary key. A primary key can only contain unique and not null values in the
relational database table.