2
Hello, I am trying to add a foreign key to an already created table and it gives the following error:
Error(s), Warning(s):
Incorrect syntax near the keyword 'Foreign'.
I tried some modifications in the syntax, but I am not able to correct the error.
That’s the code I’m using:
create table justificativa
(
CODIGO char(5) not null,
IDSt char(5) not null,
primary key(CODIGO)
);
create table situacao
(
IDSt char(5) not null,
ORIGEM char(5) not null,
CODIGO char(5) not null,
IDC char(5) not null,
primary key(IDSt),
foreign key (CODIGO) references justificativa
);
ALTER TABLE justificativa
ADD FOREIGN KEY (IDSt)
REFERENCES situacao(IDSt);
Does anyone have any idea why this is happening?
I’m using rextester.com to run the code.
Which database are you using? on which query or line is causing the error?
– gmsantos