I have created some SQL code to create 7 tables based off an ERD.
It seems to be extremely close to working, except that it says that
column “inv_no” referenced in foreign key constraint does not exist
However, the table invoice which inv_no is in is created, and has the column inv_no so I am very confused how it does not exist to create the other table invoiceLine which requires inv_no as a foreign key.
Here is my code:
CREATE TABLE invoice(
inv_no INTEGER NOT NULL,
cust_id INTEGER NOT NULL,
inv_date DATE NOT NULL,
CONSTRAINT PK_invoice_inv_no PRIMARY KEY(inv_no),
CONSTRAINT FK_customer_cust_id FOREIGN KEY(cust_id) REFERENCES customer(cust_id)
);
CREATE TABLE invoiceLine(
inv_line_no INTEGER NOT NULL,
inv_line_qty INTEGER NOT NULL,
CONSTRAINT PK_invoiceLine_inv_line_no PRIMARY KEY(inv_line_no),
CONSTRAINT FK_invoice_inv_no FOREIGN KEY(inv_no) REFERENCES invoice(inv_no)
);
Again, the table in question is invoiceLine which seems to be dependent on inv_no in the invoice table.
If anyone can spot my error that would be great!
The error message is correct there is no column
inv_noin invoiceline. You need to declare that column as well:CREATE TABLE invoiceLine( inv_no INTEGER NOT NULL, inv_line_no INTEGER NOT NULL, inv_line_qty INTEGER NOT NULL, CONSTRAINT PK_invoiceLine_inv_line_no PRIMARY KEY(inv_line_no), CONSTRAINT FK_invoice_inv_no FOREIGN KEY(inv_no) REFERENCES invoice(inv_no) );