0
4.4kviews
Explain Referential integrity.
1 Answer
written 8.4 years ago by |
Consider the situation where we have two tables: Employees and Managers. The Employees table has a foreign key attribute entitled Managed By which points to the record for that employee’s manager in the Managers table.
Referential integrity enforces the following three rules:
Let's first create Employee and Department table with primary key, foreign key and referential Integrity constraints.
CREATE TABLE Department (dept_id INT NOT NULL,
dept_name VARCHAR(256),
PRIMARY KEY (dept_id)) ENGINE=INNODB;
CREATE TABLE Employee (emp_id INT NOT NULL,
emp_name VARCHAR(256),
dept_id INT,
FOREIGN KEY (dept_id) REFERENCES Department(dept_id)
ON DELETE CASCADE) ENGINE=INNODB;