I have a table and I need to restrict the data inserted, I already use a trigger but I was wondering if I could do the same task with a constraint.
The fields are:
Id
Date
Passport
...
Deleted
The constraint must allow n records while the Deleted field is 1, but if the Deleted field is 0 there must be only one row with the same Date and Passport.
Should work for this steps:
- Adding a row with Id=1, Date=2018-05-01, Passport=MPEUIE80, Deleted=0
- Deleting the row with Id=1, so the field Deleted will be 1
- Adding a row with Id=2, Date=2018-05-01, Passport=MPEUIE80, Deleted=0
- Deleting the row with Id=2, so the field Deleted will be 1
- Adding a row with Id=3, Date=2018-05-01, Passport=MPEUIE80, Deleted=0
- Adding a row with Id=4, Date=2018-05-01, Passport=MPEUIE80, Deleted=0
Till the fifth step, everything works, but in the last step there must be an error, that is because I can't handle two rows with the same Date, same Passport and both with Deleted=0
Thanks in advance.