I’m trying to create a table with a foreign key using SQL command but I keep getting this error
Invalid field definition 'CUS_CODE' in definition of index or relationship.
I’m using this command:
CREATE TABLE INVOICE(
INV_NUMBER CHAR(5) NOT NULL,
INV_DATE DateTime NOT NULL,
CONSTRAINT INV_PK PRIMARY KEY(INV_NUMBER),
CONSTRAINT INV_FK FOREIGN KEY(CUS_CODE) REFERENCES CUSTOMER(CUS_CODE)
);
It’s because
Cus_codeis not a field in your invoice table.It should be :
Here’s an tutorial about SQL FOREIGN KEY
It should help you to illustrate what it should looks like