Unique Index that Allows NULLS

suggest change

A 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.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents