Unique constraint with a twist

Hi,

I'm not sure if this is possible, so hopefully you'll be able to help me .

I want to ensure that values in one column are unique in thier group (which is stored in a second column)

For example:

ID Name Group

1 ABC G1

2 ABC G1 would be invalid because ABC is already in group 1

3 ABC G2 would be OK because it's in group 2

Thanks in advance!



Answer this question

Unique constraint with a twist

  • Elliott_Ward

    HI,

    you have to create a compound key, either within the Create Table statement or as a separate statement

    CONSTRAINT UQ_CompoundOne UNIQUE (col1, col2)

    See more information in the bOL

    HTH, Jens Suessmeyer.

    ---
    http://www.sqlserver2005.de
    ---


  • Unique constraint with a twist