Foreign Key Constraints
Let's look at this in the context of a primary key. When this primary key is referenced by a column in another table, this primary key becomes the foreign key of the other table. For example, consider the previously created database PACKT_ONLINE_SHOP
:
DROP DATABASE IF EXISTS PACKT_ONLINE_SHOP; CREATE DATABASE IF NOT EXISTS PACKT_ONLINE_SHOP; USE PACKT_ONLINE_SHOP; CREATE TABLE Customers ( CustomerID INT NOT NULL AUTO_INCREMENT, FirstName CHAR(50) NOT NULL, LastName CHAR(50) NOT NULL, Address CHAR(250) NULL, Email CHAR(200) NULL, Phone CHAR(50) NULL, Notes VARCHAR(750) NULL, BalanceNotes VARCHAR(750) NULL, PRIMARY KEY (CustomerID) ); CREATE TABLE Orders ( OrderID INT NOT NULL AUTO_INCREMENT, ...