Search code examples
psqlalter

I want to add constraint using alter command in psql


I have created a table.

But I need to add a constraint for price that price must be greater than 10.

How it can be done using alter command....


Solution

  • You can do this with the check command.

    CREATE TABLE test (
      testCol INTEGER DEFAULT 0 NOT NULL
    );
    ALTER TABLE test
    ADD CONSTRAINT ck_value CHECK (testCol > 10);
    

    SQL Fiddle