Index: Avoid duplicates in table when Status = 'S'

Viewed 119

Is there a way of avoid duplicate rows only when status = 'S'? Example:

table showing what I need to do.

I tried to create an index "unique" but when status = 'N' it should allow duplicate, then it did not work correctly.

Any sugestions to avoid duplicates in SQL?

1 Answers

Yes, you could use filtered index:

CREATE UNIQUE INDEX UIX_name ON tab(fk_client) WHERE status = 'S';
Related