Constraints in DBMS

 Constraints in DBMS

  • Constraints are the enforced restrictions rules, imposed on the database, table column, table, and their operations (inserted/updated/deleted).
  • They ensure the correct data in the database(accuracy) and maintain the data integrity (as to reliability) during an operation into a table.

 Integrity Constraints

  • Integrity constraint is a set of rules used to maintain the quality of information.
  • It ensures that the DML operations do not affect data integrity and ensure the correct data in the database.
  • It is a guard against accidental damage in the database.

o    Relational constraints are the restrictions imposed on the database contents and operations.

 

Types of Integrity Constraint


1. Domain constraints

  • Domain constraints are defined as the valid set of values for an attribute.
  • Domain data type includes string, character, integer, time, date, currency, etc.
  • The attribute value must be atomic and correspond to the domain.

Example:


2. Entity integrity constraints

  • The entity integrity constraint defines the primary key value can't be null.
  • The primary key value is used to identify individual rows in the table and if the primary key has a null value, then we can't identify those rows.
  • A table can contain a null value other than the primary key field.

Example:


3. Referential Integrity Constraints

This constraint is enforced when a foreign key references the primary key of a relation.

o  It specifies, all the values of the foreign key either be available in the primary key relation or be null.

  • Do not insert a record into a referencing table if the corresponding record does not exist in the referenced table.
  • Do not delete or update a record of the referenced table if the corresponding record exists in the referencing table.
  • A referential integrity constraint is specified between two tables.
  • In the Referential integrity constraints, if a foreign key in Table 1 refers to the Primary Key of Table 2, then every value of the Foreign Key in Table 1 must be null or be available in Table 2.

Example:


4. Key constraints

  • Keys are the entity set that is used to identify an entity within its entity set uniquely.
  • An entity set can have multiple keys, but out of which one key will be the primary key.
  • A primary key can contain a unique and not null value in the relational table.

Example:



Post a Comment

0 Comments