Adynh
Adynh

Reputation: 219

Facing error while Altering table in PostgreSQL

I was creating tables in PostgreSQL. Then I had to use an column as foreign key so I altered my table to define that column as foreign key. But I got an error at "WITH",

ALTER TABLE Account  WITH NOCHECK ADD  CONSTRAINT FK_Account_AccountCPCMapping FOREIGN KEY(nAccountCPCMappingID)
REFERENCES AccountCPCMapping (nAccountCPCMappingID);

I am getting error like,

ERROR:  syntax error at or near "WITH"
LINE 1: ALTER TABLE Account  WITH NOCHECK ADD  CONSTRAINT FK_Account...

Please suggest any corrections.

Upvotes: 0

Views: 424

Answers (1)

Vao Tsun
Vao Tsun

Reputation: 51446

you try to use Microsoft sql server syntax https://learn.microsoft.com/en-us/sql/t-sql/statements/alter-table-transact-sql

while Postgres syntax https://www.postgresql.org/docs/current/static/sql-altertable.html is

...ADD table_constraint [ NOT VALID ]

Upvotes: 2

Related Questions