Hello, I want to create tables in database (using SQL) and add foreign keys to each table refering to the other one. For example:
CREATE TABLE ONE(
ID INT NOT NULL,
NAME VARCHAR(20) NOT NULL,
TWOID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (TWOID) REFERENCES TWO (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
CREATE TABLE TWO(
ID INT NOT NULL,
NAME VARCHAR(20) NOT NULL,
ONEID INT NOT NULL,
PRIMARY KEY (ID),
FOREIGN KEY (ONEID) REFERENCES ONE (ID) ON DELETE CASCADE ON UPDATE CASCADE
);
When I run this query, it will give me the following error "missing right parenthesis", I tried to add CONSTRAINT fk1 FOREIGN KEY.... but it didn't change anything ...
I also tried to remove the ON DELETE CASCADE ON UPDATE CASCADE, the error message changed to "table or view does not exist", which logically is correct since I am calling the table "TWO" which is not created yet but will be created later.
How to fix both problems: "missing right parenthesis" and "table or view does not exist"
Thank you