If I already have a primary key on the column Id
and I have a column Name
on which I want to add a Unique constraint
, how can I do that in SQL Server?
I tried the following:
ALTER TABLE dbo.Hotels ADD CONSTRAINT
UNQ_NAME UNIQUE NONCLUSTERED
(
Name
)
Error:
Msg 1919, Level 16, State 1, Line 1
Column 'Name' in table 'Hotels' is of a type that is invalid for use as a key column in an index.
Name
is represented as:
Name nvarchar(MAX) Allow Nulls