We define foreign key like this FOREIGN KEY(name) REFERENCES User(name) or something like this. Why and when do we need to use constraint? I don’t quite get the purpose of constraint.
We define foreign key like this FOREIGN KEY(name) REFERENCES User(name) or something like this.
Share
The purpose of the constraint on the foreign key is to ensure that you cannot delete the record in the main table while there are still references to it in other tables. If there was no constraint you would get invalid data in your database and the referential integrity would be violated.