DBMS Integrity Constraints
Integrity constraints are the set of predefined rules that are used to maintain the quality of information. Integrity constraints ensure that the data insertion, data updating, data deleting and other processes have to be performed in such a way that the data integrity is not affected. They act as guidelines ensuring that data in the database remain accurate and consistent. So, integrity constraints are used to protect databases. The various types of integrity constraints are
Types of Integrity Constraints
There are four types of integrity constraints which are:
- Domain Constraints
- Entity integrity Constraints
- Key Constraints
- Referential integrity constraints
Domain Constraints
These are defined as the defination of valid set of values for an atribute. The data type of domain include string, char, time, integer, date, currency etc. The value of the attribute must be avialable in comparable domains.
Example:
Student_Id |
Name |
Semester |
Age |
---|---|---|---|
21CSE100 |
Ramesh |
5th |
20 |
21CSE101 |
Kamlesh |
5th |
21 |
21CSE102 |
Aakash |
5th |
22 |
21CSE103 |
Mukesh |
5th |
20 |
Entity Integrity Constraints
Entity integrity constraints state that primary key can never contain null value because primary key is used to determine individual rows in a relation uniquely, if primary key contains null value then we cannot identify those rows. A table can contain null value in it except primary key field.
Example:
It is not allowed because it is containing primary key as NULL value.
Student_id |
Name |
Semester |
Age |
---|---|---|---|
21CSE101 |
Ramesh |
5th |
20 |
21CSE102 |
Kamlesh |
5th |
21 |
21CSE103 |
Aakash |
5th |
22 |
Mukesh |
5th |
20 |
Key Constraints
Keys are the entity set that are used to identify an entity within its entity set uniquely. An entity set can contain multiple keys, bit out of them one key will be primary key. A primary key is always unique, it does not contain any null value in table.
Example:
Student_id |
Name |
Semester |
Age |
---|---|---|---|
21CSE101 |
Ramesh |
5th |
20 |
21CSE102 |
Kamlesh |
5th |
21 |
21CSE103 |
Aakash |
5th |
22 |
21CSE102 |
Mukesh |
5th |
20 |
It is now acceptable because all rows must be unique.
Referential integrity constraints
It can be specified between two tables. In case of referential integrity constraints, if a Foreign key in Table 1 refers to Primary key of Table 2 then every value of the Foreign key in Table 1 must be null or avialable in Table 2.
Example:
Here, in below example Block_No 22 entry is not allowed because it is not present in 2nd table.
Student_id |
Name |
Semester |
Block_No |
---|---|---|---|
22CSE101 |
Ramesh |
5th |
20 |
21CSE105 |
Kamlesh |
6th |
21 |
22CSE102 |
Aakash |
5th |
20 |
23CSE106 |
Mukesh |
2nd |
22 |
Block_No |
Block Location |
---|---|
20 |
Chandigarh |
21 |
Punjab |
25 |
Delhi |
Conclusion
Integrity constraints act as the backbone of reliable and robust database. They ensure that the data stored is reliable, worthy, consistent and accurate within the database. By implement integrity constraints we can improve the quality of the data stored in database. So, as the database continues to grow it will not become inconsistent and inaccurate.
Frequently Asked Questions on Integrity Constraints – FAQs
What are integrity constraints and why are they important in database?
Integrity constraints are predefined rules which ensures the quality of the information in databases. They maintain data accuracy and consistency by guiding the operations like data insertion, data deletion and data updation. These are important for protecting the integrity of the database.
What are the key types of integrity constraints and, how do they differ?
Basically there are four types of integrity constraints these are Domain constraints, Entity integrity constraints, key constraints and Referential integrity constraints. Each type of these serve their purpose in maintaining data integrity.
How do domain constraints contribute to data integrity in databases?
Domain constraints define valid sets of values for attributes, ensuring that data entered into the database adhere to specified data types and formats. By enforcing these constraints, databases maintain consistency and accuracy of data, preventing the insertion of incorrect or incompatible values.
Contact Us