A foreign key in MySQL is a field in a table that is used to link two tables together. It is used to ensure data integrity and to enforce referential integrity.

For example, if you have two tables, ‘Customers’ and ‘Orders’, you could use a foreign key in the ‘Orders’ table that references the ‘CustomerID’ field in the ‘Customers’ table. This would ensure that any order placed in the ‘Orders’ table is associated with an existing customer in the ‘Customers’ table.

Leave a Reply

Your email address will not be published. Required fields are marked *