FOREIGN KEYS just make sure your data is consistent.
They do not improve queries in terms of efficiency, they just make the wrong queries.
If you have such a relationship:
CREATE TABLE department (id INT NOT NULL) CREATE TABLE employee (id INT NOT NULL, dept_id INT NOT NULL, FOREIGN KEY (dept_id) REFERENCES department(id))
you cannot delete department if it has employee .
If you specify ON DELETE CASCADE in the FOREIGN KEY definition, the reference lines will be automatically deleted along with the specified ones.
As a limitation, FOREIGN KEY actually slows down queries a bit.
Additional validation should be performed when deleting from a table with links or pasting into a link.
Quassnoi Apr 16 '09 at 17:30 2009-04-16 17:30
source share