Unique Index that Allows NULLS
suggest changeA WHERE predicate on CREATE INDEX is a filtered (partial) index, used by SQL Server, PostgreSQL, and SQLite. GO is a SQL Server client batch separator. In SQL Server a unique index allows only one NULL unless the NULLs are filtered out, as here.
CREATE UNIQUE INDEX idx_license_id
ON Person(DrivingLicenseID) WHERE DrivingLicenseID IS NOT NULL
GO
This schema allows a 0..1 relationship: a person can have zero or one driving licenses, and each license value belongs to only one person.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents