Link to home
Start Free TrialLog in
Avatar of CodeWrangler
CodeWrangler

asked on

Need a UNIQUE constrain on multiple cols in a SQL Server table but one of the cols is by VALUE

Say I have this simple example table

username varchar(100),
active char(1),
date_deactivated datetime

I need to have a UNIQUE constraint on this table where there can only be one username that has active="y". There can be any number of the same username and "n" rows. Appreciate the help in advance.
ASKER CERTIFIED SOLUTION
Avatar of Scott Pletcher
Scott Pletcher
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of CodeWrangler
CodeWrangler

ASKER

Thanks a ton!!
just curious, how much will this affect performance. I know you only have limited information about my table and it's design, but strictly from this approach of having a index use a computer column, which might be the performance impact.
Virtually zilch.  There's some slight overhead to generating an identity column, but most people use one in a table anyway.