Maryam
Maryam

Reputation: 19

I want to add a constraint to my table but an error keeps on showing

CREATE TABLE products
(
    id_product INT,
    name_prod VARCHAR2(100),
    category_prod VARCHAR2(255),
    Date_exp DATE,
    Qt_stock number,
    price INT ,
    CONSTRAINT prod PRIMARY KEY(id_product),
    CONSTRAINT c1 FOREIGN KEY(id_supp)REFERENCES supplier(id_supp)
)
**************************
CREATE TABLE supplier
(
  id_supp INT, 
  supp_name VARCHAR2(50),
  date_comm DATE,
  Address VARCHAR2(255),
  nombre_comm INT,
  CONSTRAINT supp PRIMARY KEY(id_supp)
)

the id_supp is a column and a primary key in table supplier but

invalid identifier

appears every time, how can I fix it?

Upvotes: 0

Views: 53

Answers (1)

juergen d
juergen d

Reputation: 204756

You need to create the supplier table first.

Then you can refer to it as foreign key. And you need to add that column to your products table:

CREATE TABLE products
(
    id_product INT,
    name_prod VARCHAR2(100),
    category_prod VARCHAR2(255),
    Date_exp DATE,
    Qt_stock number,
    price INT ,
    id_supp INT,
    CONSTRAINT prod PRIMARY KEY(id_product),
    CONSTRAINT c1 FOREIGN KEY(id_supp)REFERENCES supplier(id_supp)
)

Demo

Upvotes: 5

Related Questions