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?
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.
Perhaps you are referring to the following statement from SQL92:
- A unique constraint is satisfied if and only if no two rows in a table have the same non-null values in the unique columns.
That statement is ambiguous, having at least two possible interpretations:
A unique constraint is satisfied if and only if no two rows in a table have the same values and have non-null values in the unique columns.
A unique constraint is satisfied if and only if no two rows in a table have the same values in the subset of unique columns that are not null.
SQLite follows interpretation (1), as does PostgreSQL, MySQL, Oracle, and Firebird. It is true that Informix and Microsoft SQL Server use interpretation (2), however we the SQLite developers hold that interpretation (1) is the most natural reading of the requirement and we also want to maximize compatibility with other SQL database engines, and most other database engines also go with (1), so that is what SQLite does.
See a comparison of NULL handling.