I have a 'Users' table where I want to make the 'Phone' column unique. Currently the 'PhoneNumber' column allow null. I'm using the following script.
ALTER TABLE dbo.Users
ADD CONSTRAINT Unique_PhoneNumber
UNIQUE NONCLUSTERED (PhoneNumber)
The problem is, there is 300+ rows in the 'Users' table. Half of them have a Null value. When I run the script it says complete successfully. However after refreshing the table constraints in Management studio, the constraint did not appear and is not applied to that column when adding a new user.
Note: If I try to run the script again, I get a duplicate error, like the constraint already exist.
Anyone know what I need to do in order to get the column unique?