Last answered:

27 Aug 2020

Posted on:

24 Aug 2020

0

SQL Syntax

For creating a foreign key will the below code be appropriate?
CREATE TABLE items
(
item_id VARCHAR(255),
item VARCHAR(255),
unit_price NUMERIC(10,2),
company_id VARCHAR(255) FOREIGN KEY,
PRIMARY KEY(item_id)
);

1 answers ( 0 marked as helpful)
Posted on:

27 Aug 2020

0
A foreign key refers to a column in another table. So you need to use References key word and specify the other table name and column in the foreign key constraint.    This is what the script will look like in MySQL.  CREATE TABLE items
(
item_id VARCHAR(255),
item VARCHAR(255),
unit_price NUMERIC(10,2),
company_id VARCHAR(255) FOREIGN KEY,
PRIMARY KEY(item_id), FOREIGN KEY (company_id)  REFRENCES company(company_id));

Submit an answer