Skip to main content

Featured

functions in Python

How to create foreign key in Mysql

How to create foreign key in Mysql ?

Suppose we want to create two tables Suppliers and Orders. The Supp_Id in Suppliers Table is Primary key. The Supp_ID in Orders table is Foreign Key which references the values from Suppliers Table.  

CREATE TABLE Suppliers
(
Supp_Id int NOT NULL primary key,
Supp_Name char(30) NOT NULL,
Supp_City char(30) NOT NULL
)

CREATE TABLE Orders
(
Order_Id int NOT NULL,
Order_No int NOT NULL,
Supp_Id int,
PRIMARY KEY (Order_Id),
FOREIGN KEY (Supp_Id) REFERENCES Suppliers(Supp_Id)
)


Mysql Screen Output:


Comments

Post a Comment

Popular Posts