Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
iceice
Starting Member
5 Posts |
Posted - 2012-05-02 : 10:04:32
|
table has primary key column and "orderid" nvarchar(30) column. table has many records. "orderid" column must be unique.how to set this column as unique? |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-05-02 : 10:35:38
|
If it's set at the primary key it's already unique. |
 |
|
iceice
Starting Member
5 Posts |
Posted - 2012-05-02 : 10:46:05
|
primary key column and "orderid" column are different. "orderid" column has null values too. |
 |
|
robvolk
Most Valuable Yak
15732 Posts |
Posted - 2012-05-02 : 11:59:56
|
Ah, misread the question. You can't put a unique constraint on orderid if it has multiple nulls. You either have to update them to be unique, delete them from the table, or create a unique filtered index:CREATE UNIQUE INDEX ix_UNQ_orderID ON myTable(orderid) WHERE orderid IS NOT NULL This will work on SQL Server 2008 or higher. |
 |
|
|
|
|