Foreign Key
Foreign keys are a set of constraints in DBMS that establish relationships between tables and also ensure consistency and integrity of data. A foreign key is applied to a column of one table which references the primary key of a column in another table.
Note that it is mandatory that the other column must have a primary key as it references the data that is related in different tables and creates a relational structure. Foreign key enforces referential integrity and makes sure that data is referenced from one table to table. In order to create a Foreign key we will specify the relationship between the columns during the creation of the table’s structure. We add the keyword REFERENCES in order to specify that this particular column will refer to another column of another table.
Also, note that it is possible for a foreign key of a column to reference a column in the table itself. For this to happen the referenced column should be a primary key and this is called Self-Reference.
In this article, we will thoroughly implement foreign keys in DBMS with the help of MYSQL as we perform all the operations in a table that is inside a database.
Foreign Key in DBMS
In DBMS, there are different types of keys available that are used for various purposes. Foreign Key is a column that refers to the primary key/unique key of another table. So it demonstrates the relationship between tables and acts as the cross reference among them.
Contact Us