What is referential integrity constraint in SQL
Olivia Owen
Published Apr 22, 2026
Referential Integrity is a set of constraints applied to foreign keys which prevents entering a row in the child table (where you have the foreign key) for which you don’t have any corresponding row in the parent table i.e. entering NULL or invalid foreign keys.
What is referential integrity constraint explain with example?
A foreign key constraint (also referred to as a referential constraint or a referential integrity constraint) is a logical rule about values in one or more columns in one or more tables. For example, a set of tables shares information about a corporation’s suppliers. Occasionally, a supplier’s name changes.
What is meant by referential constraints?
A referential constraint is defined for a specific column (called a foreign key) when a table is defined. A table in which a referential constraint and a foreign key are defined is called a referencing table, while a table that is referenced from a referencing table with a foreign key is called a referenced table.
What is referential integrity in a database?
Referential integrity is a property of data stating that all its references are valid. … For referential integrity to hold in a relational database, any column in a base table that is declared a foreign key can only contain either null values or values from a parent table’s primary key or a candidate key.How does delete cascade work?
Use the ON DELETE CASCADE option to specify whether you want rows deleted in a child table when corresponding rows are deleted in the parent table. If you do not specify cascading deletes, the default behavior of the database server prevents you from deleting data in a table if other tables reference it.
Which is an example of referential integrity?
Referential integrity requires that a foreign key must have a matching primary key or it must be null. … Examples of referential integrity constraint in the Customer/Order database of the Company: Customer(CustID, CustName) Order(OrderID, CustID, OrderDate)
Why is referential integrity constraint important?
Referential integrity (RI)is a method for ensuring the “correctness” of data within a DBMS. People tend to oversimplify RI, stating that it is merely the identification of relationships between relational tables.
What is the use of referential integrity?
Referential integrity (RI) is a term used with relational databases to describe the integrity of the business relationships represented in the schema. It ensures that relationships between tables remain consistent.What is Cascade update in a database?
The Cascade Update utility allows Administrators to maintain database integrity and consistency by altering or deleting the data in one or more dependent files to match changes made to data in a source file.
How do you do referential integrity in SQL?Using Referential Integrity Constraints. Whenever two tables are related by a common column (or set of columns), define a PRIMARY or UNIQUE key constraint on the column in the parent table, and define a FOREIGN KEY constraint on the column in the child table, to maintain the relationship between the two tables.
Article first time published onWhat is referential integrity in tableau?
Referential Integrity: a value in one table is guaranteed to have a match in the other table. In other words, there can’t be a record in one table that does not have a corresponding record in the other table.
What is referential integrity & how can we achieve it?
Referential integrity ensures that key values are consistent across tables. Such consistency requires that there be no references to nonexistent values and that if a key value changes, all references to it change consistently throughout the database. We can achieve this by using foreign key.
What is the difference between on delete set null and on delete cascade?
Set NULL : Sets the column value to NULL when you delete the parent table row. CASCADE : CASCADE will propagate the change when the parent changes. If you delete a row, rows in constrained tables that reference that row will also be deleted, etc.
What is cascade update and delete?
CASCADE. It is used in conjunction with ON DELETE or ON UPDATE. It means that the child data is either deleted or updated when the parent data is deleted or updated. SET NULL. … It means that the child data is set to their default values when the parent data is deleted or updated.
When should I delete cascade?
Use cascade delete where you would want the record with the FK to be removed if its referring PK record was removed. In other words, where the record is meaningless without the referencing record. I find cascade delete useful to ensure that dead references are removed by default rather than cause null exceptions.
What happens without referential integrity?
A lack of referential integrity in a database can lead to incomplete data being returned, usually with no indication of an error. This could result in records being “lost” in the database, because they’re never returned in queries or reports.
Why foreign key is called referential integrity?
Referential integrity refers to the relationship between tables. Because each table in a database must have a primary key, this primary key can appear in other tables because of its relationship to data within those tables. When a primary key from one table appears in another table, it is called a foreign key .
What is referential integrity in mysql?
Simply put, referential integrity means that when a record in a table refers to a corresponding record in another table, that corresponding record will exist.
What is meant by delete cascade in SQL?
DELETE CASCADE: When we create a foreign key using this option, it deletes the referencing rows in the child table when the referenced row is deleted in the parent table which has a primary key. … Triggers on a table with DELETE or UPDATE cascading foreign key.
What does delete on Cascade mean?
ON DELETE CASCADE constraint is used in MySQL to delete the rows from the child table automatically, when the rows from the parent table are deleted. For example when a student registers in an online learning platform, then all the details of the student are recorded with their unique number/id.
What is referential integrity constraint in Oracle?
Referential integrity is a database constraint that ensures that references between data are indeed valid and intact. … By specifying the DEPTNO column as the primary key of the DEPARTMENT table and WORKDEPT as the foreign key of the EMPLOYEE table, you are defining a referential constraint on the WORKDEPT values.
What are the rules of referential integrity?
A referential integrity rule is a rule defined on a key (a column or set of columns) in one table that guarantees that the values in that key match the values in a key in a related table (the referenced value).
What is cardinality of table?
In SQL (Structured Query Language), the term cardinality refers to the uniqueness of data values contained in a particular column (attribute) of a database table. The lower the cardinality, the more duplicated elements in a column.
How many filters are there in Tableau?
There are six different types of filters in tableau desktop based on their various objectives and are mentioned below as per their execution steps.
What do you mean by referential integrity Class 10?
Referential integrity. It means the reference from a row in one table to another table must be valid.
What is Composite key give an example?
In a table representing students our primary key would now be firstName + lastName. Because students can have the same firstNames or the same lastNames these attributes are not simple keys. The primary key firstName + lastName for students is a composite key.
How does update cascade work?
The ON UPDATE CASCADE tells the database that when an update occurs on the referenced column from the parent table (“ id ”), it must automatically update the matching rows in the child table (“ books ”) with the new value.
Can primary key be NULL?
The PRIMARY KEY constraint uniquely identifies each record in a table. Primary keys must contain UNIQUE values, and cannot contain NULL values.
What does on update restrict mean?
RESTRICT prevents the action from happening if there’s any foreign keys that rely on the field that’s being changed.
What is on delete no action?
NO ACTION means that nothing will happen when you delete from your Subject table to the Topic table. In that case, if there is a row in Topic for a given SubjectId you cannot delete from it without breaking referential integrity, so the Delete will be rolled back.
What is on delete restrict?
The ON DELETE clause says that if a particular primary key ID value in the CUSTOMERS table is deleted, this action shall be prevented (this is the “restrict” part) if there is any row in the ORDERS table which has a foreign key that matches the value of the CUSTOMER table ID value.