I have an invoice table. It has many fields, but the problem is around 2 main fields
- InvoiceNo - alphanumeric values
- Deleted - boolean 1 or 0 ,to represent a record is deleted or not.
Our business requires InvoiceNo to be unique. However if a row is deleted we can re-use the InvoiceNo
InvoiceNo Deleted
123Er 1
123Er 0
Above is a valid use case. But i don't want to have another record with 123Er & 0.
Is it possible to create unique key on combination of 2 fields for certain values Unique (InvoiceNo, Deleted=0) or should we go for stored procedure or triggers ?