Possible Duplicate:
Simple CHECK Constraint not so simple
we have a table with roles for a user. It looks like this:
Id, RoleId, PersonId, Active
The active column is used for softdelete functionallity: when you delete a role for a user, you actually set active
to false
.
So you can have multiple rows with the same roleid-personid-active
combination, but only when the active bit is set to false.
So this is valid data:
Id RoleId PersonId Active
1 1 1 false
2 1 1 false
3 1 1 false
4 1 1 false
but this isn't, because you can have only one active role on any moment (so record 3 should not be inserted):
Id RoleId PersonId Active
1 1 1 false
2 1 1 true
3 1 1 true
My question is: can i create a unique constraint on RoleId, PersonId and Active
, where active
equals to true
?
ps. Sql server version is 2005