Featured
- Get link
- X
- Other Apps
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)
)
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:
- Get link
- X
- Other Apps
Comments
Popular Posts
C++ program to display numbers which get reversed after multiplying by 4
- Get link
- X
- Other Apps
need some more examples
ReplyDelete