I noticed that I can have NULL values in columns that have the UNIQUE constraint: UNIQUE(col)
Would that generate any issues in certain situations?
I noticed that I can have NULL values in columns that have the UNIQUE constraint: UNIQUE(col)
Would that generate any issues in certain situations?
If you want your unique index to throw an error when a two rows would be the same if you disregard NULL columns (and don't want to use triggers from Satyam's answer) you can do something like this
While the following addresses multiple null values, it does not address any "issues" associated with such a design, other than possible database/SQL portability - as such, it should probably not be considered an answer, and is left here merely for reference.
This is actually covered in the SQLite FAQ. It is a design choice - SQLite (unlike SQL Server) chose that multiple NULL values do not count towards uniqueness in an index.
The SQL standard requires that a UNIQUE constraint be enforced even if one or more of the columns in the constraint are NULL, but SQLite does not do this. Isn't that a bug?
See a comparison of NULL handling.
You can create 2 triggers on table to check if a row with column as null exists before any insert or update operation, if so raise exception.