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 between0
and120
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.
- In
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.
- If
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)
referencesCustomers(CustomerID)
, everyCustomerID
inOrders
must exist inCustomers
.
- If
Summary Table
Constraint Type | Description | Example |
---|---|---|
Domain Constraint | Values must match the attribute’s defined data type/range | Age must be a number |
Key Constraint | Uniquely identify rows using keys | RollNo is unique for every student |
Entity Integrity | Primary key cannot be null | EmployeeID must have a value |
Referential Integrity | Foreign keys must match values in the parent table | Orders.CustomerID must exist in Customers |