Explain the different Relational Model constraints

Explain the different Relational Model constraints

Answer:-

In the Relational Model of DBMS, constraints are rules that ensure data accuracy, integrity, and consistency in a database.

There are 4 main types of relational model constraints:


1. Domain Constraints

  • Restrict the type of values that attributes (columns) can hold.
  • Each attribute must contain only values from a defined domain (data type or range).
  • Example:
    • Age must be an integer between 0 and 120
    • Email must be a string (varchar)

2. Key Constraints

  • Ensure uniqueness of rows (tuples) in a table.
  • There are two types:
    • Primary Key: Uniquely identifies each row. Cannot be null.
    • Candidate Key: A set of fields that could serve as a primary key.
  • Example:
    • In Students(RollNo, Name, Age), RollNo is the primary key.

3. Entity Integrity Constraint

  • States that primary key of a table cannot be null.
  • Because each entity (row) must be uniquely identifiable.
  • Example:
    • If EmployeeID is a primary key, it must have a value for every employee.

4. Referential Integrity Constraint

  • Ensures that a foreign key in one table correctly refers to an existing primary key in another table.
  • Prevents orphan records (i.e., references to non-existent rows).
  • Example:
    • If Orders(CustomerID) references Customers(CustomerID), every CustomerID in Orders must exist in Customers.

Summary Table

Constraint TypeDescriptionExample
Domain ConstraintValues must match the attribute’s defined data type/rangeAge must be a number
Key ConstraintUniquely identify rows using keysRollNo is unique for every student
Entity IntegrityPrimary key cannot be nullEmployeeID must have a value
Referential IntegrityForeign keys must match values in the parent tableOrders.CustomerID must exist in Customers

Leave a Reply

Your email address will not be published. Required fields are marked *