Constraints in Relational Algebra

When designing Relational Model, we define some conditions which must hold for data present in database are called Constraints. These constraints are checked before performing any operation (insertion, deletion and updation) in database. If there is a violation in any of constrains, operation will fail.

Domain Constraints:  These are attribute level constraints. An attribute can only take values which lies inside the domain range. For example if a constrains AGE>0 is applied on STUDENT relation, inserting negative value of AGE will result in failure.

Key Integrity:  Every relation in the database should have at least one set of attributes which defines a tuple uniquely. Those set of attributes is called key. ROLL_NO in STUDENT is a key. No two students can have same roll number. So a key has two properties: 


  • It should be unique for all tuples.
  • It can't have NULL values.


Referential Integrity:  When one attribute of a relation can only take values from other attribute of same relation or any other relation, it is called referential integrity. For example consider the two relations



the u_id of relation Address match its value with the u_id of relation Name in order to get the user's name to match with their Addresses  which is called referential integrity constraint.  The relation which is referencing to other relation is called REFERENCING RELATION(Address in this case), and the relation to which other relations refer is called REFERENCED RELATION (Name in this case).

Next Topic :-  

No comments:

Post a Comment