Take the 2-minute tour ×  Database is MS SQLServer  Data
example:  | Name | defaultValue |  value   | | one  |     true
| valone   | | one  |     false    | valtwo   | | one  |
false    | valthree |  I'm after a way of constraining the table
such that each 'Name' can only have one row with 'defaultValue'
set to true  share|improve this question add comment  3 Answers
Create a computed column like this:    ALTER TABLE yourtable
ADD ValueCheck AS CASE defaultValue      WHEN true THEN 1
WHEN false THEN NULL  and then add unique constraint for (Name,
ValueCheck)  share|improve this answer I +1ed this but then
realised it doesn't work. Unique constraints in SQL Server only
allow 1 NULL. –  Martin Smith Jul 27 '10 at 10:30 You are right.
:( –  Michael Pakhantsov Jul 27 '10 at 10:57 If yourtable has a
key column (eg. keyid), then changing NULL to keyid above should
work. –  Mark Bannister Jul 27 '10 at 12:28 (and changing
...when true then 1... to ...when true then 0...) –  Mark
Bannister Jul 27 '10