Combining the UNIQUE and CHECK constraints

Posted by Bobby on Stack Overflow See other posts from Stack Overflow or by Bobby
Published on 2010-04-06T18:02:56Z Indexed on 2010/04/06 18:03 UTC
Read the original article Hit count: 318

Filed under:
|

I have a table with columns a b and c, and if c is false then I only want to allow insertions if columns a and b are unique, but if c is true then a and b do not need to be unique.

Example: There can only be one (foo, bar, false) in the table, but no limit on how many (foo, bar, true) there can be.

I tried something like CONSTRAINT blah UNIQUE (a,b) AND CHECK (C is TRUE) but I can't figure out the correct syntax.

© Stack Overflow or respective owner

Related posts about sql

Related posts about constraints