Here, we will learn about the violations that can occur on a database as a result of any changes made in the relation.
There are mainly three operations that have the ability to change the state of relations, these modifications are given below:
- Insert –
To insert new tuples in a relation in the database.
- Delete –
To delete some of the existing relation on the database.
- Update (Modify) –
To make changes in the value of some existing tuples.
Whenever we apply the above modification to the relation in the database, the constraints on the relational database should not get violated.
On inserting the tuples in the relation, it may cause violation of the constraints in the following way:
1. Domain constraint :
Domain constraint gets violated only when a given value to the attribute does not appear in the corresponding domain or in case it is not of the appropriate datatype.
Assume that the domain constraint says that all the values you insert in the relation should be greater than 10, and in case you insert a value less than 10 will cause you violation of the domain constraint, so gets rejected.
2. Entity Integrity constraint :
On inserting NULL values to any part of the primary key of a new tuple in the relation can cause violation of the Entity integrity constraint.
Insert (NULL, ‘Bikash, ‘M’, ‘Jaipur’, ‘123456’) into EMP
The above insertion violates the entity integrity constraint since there is NULL for the
primary key EID, it is not allowed, so it gets rejected.
3. Key Constraints :
On inserting a value in the new tuple of a relation which is already existing in another tuple of the same relation, can cause violation of Key Constraints.
Insert (’1200’, ‘Arjun’, ‘9976657777’, ‘Mumbai’) into EMPLOYEE
This insertion violates the key constraint if EID=1200 is already present in some tuple in the same relation, so it gets rejected.
Referential integrity :
On inserting a value in the foreign key of relation 1, for which there is no corresponding value in the Primary key which is referred to in relation 2, in such case Referential integrity is violated.
When we try to insert a value say 1200 in EID (foreign key) of table 1, for which there is no corresponding EID (primary key) of table 2, then it causes violation, so gets rejected.
Solution that is possible to correct such violation is if any insertion violates any of the constraints, then the default action is to reject such operation.
On deleting the tuples in the relation, it may cause only violation of Referential integrity constraints.
Referential Integrity Constraints :
It causes violation only if the tuple in relation 1 is deleted which is referenced by foreign key from other tuples of table 2 in the database, if such deletion takes place then the values in the tuple of the foreign key in table 2 will become empty, which will eventually violate Referential Integrity constraint.
Solutions that are possible to correct the violation to the referential integrity due to deletion are listed below:
- Restrict –
Here we reject the deletion.
- Cascade –
Here if a record in the parent table(referencing relation) is deleted, then the corresponding records in the child table(referenced relation) will automatically be deleted.
- Set null or set default –
Here we modify the referencing attribute values that cause violation and we either set NULL or change to another valid value
Attention reader! Don’t stop learning now. Get hold of all the important CS Theory concepts for SDE interviews with the CS Theory Course at a student-friendly price and become industry ready.
- Difference between Entity constraints, Referential constraints and Semantic constraints
- Constraints on Relational database model
- Difference between Relational Algebra and Relational Calculus
- Difference between Tuple Relational Calculus (TRC) and Domain Relational Calculus (DRC)
- Difference between Relational database and NoSQL
- Difference between CouchDB and Relational Database
- How to pre populate database in Android using SQLite Database
- Difference between Database Administrator (DBA) and Database Engineer
- Difference between Centralized Database and Distributed Database
- SQL | Constraints
- Structural Constraints of Relationships in ER Model
- Types of Keys in Relational Model (Candidate, Super, Primary, Alternate and Foreign)
- Introduction of Relational Algebra in DBMS
- Relational Model in DBMS
- Mapping from ER Model to Relational Model
- Extended Operators in Relational Algebra
- Basic Operators in Relational Algebra
- How to solve Relational Algebra problems for GATE
- Introduction of Relational Model and Codd Rules in DBMS
- Anomalies in Relational Model
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to email@example.com. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.