What to do when I want to use database constraints but only mark as deleted instead of deleting?
问题 I am working in a project where database items are not deleted, but only marked as deleted. Something like this: id name deleted --- ------- -------- 1 Thingy1 0 2 Thingy2 0 3 Thingy3 0 I would like to be able to define something like a UNIQUE constraint on the name column. Seems easy, right? Let's imagine a scenario in which "Thingy3" is deleted, and a new one is created (perhaps years later). We get: id name deleted --- ------- -------- 1 Thingy1 0 2 Thingy2 0 3 Thingy3 1 ... 100 Thingy3 0