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, Â Â Â Â ...