Table one
ID | product_code | product name | company_id
1 | 12345 | beer cake |343434defee
2 | 12346 | vodka cake |343434deereee
Table two
Product_code |Quantity | price | weight
12345 | 34 |345 |0.5
12345 | 343 |600 |1.0
12345 | 4 |845 |1.5
12346 | 341 |345 |0.5
CREATE TABLE `one`(
ID INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
product_code VARCHAR(32) NOT NULL ,
name VARCHAR(30) NOT NULL ,
company_id VARCHAR(30) NOT NULL)
CREATE TABLE two(
product_code VARCHAR(32) ,
weight VARCHAR(20) NOT NULL ,
price INT(4) NOT NULL ,
Quantity INT(4) NOT NULL ,
FOREIGN KEY (product_code) REFERENCES one(product_code))
This is what my table looks like, each type of cake has to be displayed on the product landing page.The relationship between two tables is given by the column product_code
.
Is it necessary to have a primary key in the foreign table?
Please, Show me a proper schema creation for these ?