check constraint based on other column

  • Greetings,

    I am trying to write a check constraint based on the value of another column in the same table. If the other column = 0, then the check constraint should not allow any entries into its field. Any ideas? I'm hoping not to have to use a trigger for this....

  • You'll have to add the check constraint on multiple columns, on table level that is. The next statement should do the trick

    alter table constrainttest

    add constraint two_column CHECK (other_column <> 0 OR field_to_check is null)

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply