Deprecated: mysql_connect(): The mysql extension is deprecated and will be removed in the future: use mysqli or PDO instead in /home/lsp4you/public_html/connect.php on line 2 LSP4YOU - Learner's Support Publications

Database Operations and Constraint Violations

There are three basic operations to be performed on relations:
  • Insertion
  • Deletion
  • Update

The INSERT Operation:
The insert operation allows us to insert a new tuple in a relation. When we try to insert a new record, then any of the following four types of constraints can be violated:
Domain Constraint:
If the value given to an attribute lies outside the domain of that attribute.
Key Constraint:
If the value of the key attribute in the new tuple t is the same as in the existing tuple in relation R.
Entity Integrity Constraint:
If the primary key attribute value of new tuple is given as null.
Referential Integrity Constraint:
If the value of the foreign key in t refers to a tuple that does not appear in the referenced relation.

If the insertion violates one or more constraints then
  • Insertion can be rejected and the reason for rejection can also be explained to the user by DBMS
  • or
  • Ask the user to correct the data and resubmit, also give the reason for rejecting the insertion


The DELETION Operation:
Using the delete operation some existing records can be deleted from a relation. To delete some specific records from the database a condition is also specified, based on which records can be selected for deletion.

Constraints that can be violated during deletion
Only one type of constraint can be violated during deletion, it is referential integrity constraint. It can occur when delete a record in the table where it is referenced by the foreign key of another table.
If the deletion violates referential integrity constraint, then
  • Reject the deletion
  • Attempt to cascade the deletion by deleting tuples that references the tuple that is being deleted
  • Change the value of referencing attribute that causes the violation


The UPDATE Operation:
Update operations are used for modifying database values.
The constraints violations faced by this operation are logically the same as the problem faced by Insertion and Deletion operations.