I have a VARCHAR field (in table of a MySQL database) where I need each entry to be unique compared to any other row of that same field of the entire set.
However, after I delete one of these unique strings, I want the ability to insert and update other records of this field, so that they now have this previously used unique value.
The problem is that the Unique constraint seems to remember all “deleted unique strings”, and it won’t allow me to update or add strings that were previously used (but are now deleted).
Is there another constraint, where I can specify that the set must be distinct at all times, but previously deleted unique VARCHARs are not restrained?
No, it doesn’t work like that.
Once you delete a value from a table it can be inserted again even if there is a unique constraint on the table.
One potential problem is if you use soft delete – i.e. marking the row as deleted by setting an
is_deletedfield to 1. If this is the case, then you’re right that soft deleted values will prevent the unique constraint from working as intended. But that doesn’t seem to be the case here.