Logical Delete vs Unique Index: The Duplicate Entry Trap and the Generated Column Fix
The article explains how logical deletion conflicts with unique indexes in MySQL, shows why a composite index on (code, deleted) only supports one delete-create cycle, and presents a robust solution using a generated column that becomes NULL when deleted, leveraging MySQL's allowance of multiple NULLs in unique indexes to enforce uniqueness only on active records.
