0

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.

3
  • 3
    Where in the manual did you find with nocheck? What do you expect it to do? Commented Dec 29, 2017 at 9:50
  • 1
    I'm assuming you are looking for NOT VALID; it goes at the very end of your query and will prevent PostgreSQL from checking existing rows against this constraint. Commented Dec 29, 2017 at 10:01
  • nocheck is SQLserver syntax and novalidate - oracle Commented Dec 29, 2017 at 10:39

1 Answer 1

2

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 ]

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.