Reputation: 83
I want to define an unique column, but only when it's not null.
What I mean is there can be multiple null values, but when they're not null they must be different. How can I do this?
Upvotes: 1
Views: 238
Reputation: 204746
In SQL Server 2008 and above you can specify a condtion on your index
CREATE UNIQUE NONCLUSTERED INDEX IX_Filtered_Index_Name ON your_table (some_column)
WHERE some_column IS NOT NULL
Upvotes: 4