i had a problem with my sql program with foreign keys


create table purchase (
    foreign key (item_name) references inventory(item_name)

The column referenced by the foreign key needs a unique index: inventory(item_name) does not have that. I would simply recommend referencing the primary key of inventory rather than some other column:

create table purchase (
    purchase_date date,
    purchase_count int, 
    customer_id int,
    item_id int,
    foreign key (customer_id) references customer(customer_id),
    foreign key (item_id) references inventory(item_id)

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top