Reputation: 2149
I have a UNIQUE constraint for columns username + user_status, such that we never allow two users that have the same name and status. However I wish this to apply only to the case where the status field is 'ACTIVE' but allow any number of records with the same username and status of 'INACTIVE'. Is this possible?
Upvotes: 0
Views: 43
Reputation:
You can create a filtered unique index:
create unique index on the_table (username)
where user_status = 'ACTIVE';
Upvotes: 5