From: bill on
Got a bunch of tables from an exernal app that don't have Primary Keys
defined, but they do have unique indexes. I need to add a primary key
for replication.

I would like to add a primary key to these tables, but I want to say
"Don't make a new index to enforce the primary key, just use the
existing unique index."

I can't find any indication in the docs that SQL Server can do this,
but thought I would check.

Thanks,

Bill
From: Gert-Jan Strik on
Bill,

What you want is not possible. Whenever you create a Primary Key
constraint or Unique constraint, SQL Server will create a unique index
to enforce the constraint. This index cannot be prevented or dropped, it
is tied to the constraint.

So if you have to create Primary Keys, your best approach would be to
drop the existing unique indexes afterwards. Or drop them before you
create the Primary Key in case the existing index is a clustered index.

--
Gert-Jan

bill wrote:
>
> Got a bunch of tables from an exernal app that don't have Primary Keys
> defined, but they do have unique indexes. I need to add a primary key
> for replication.
>
> I would like to add a primary key to these tables, but I want to say
> "Don't make a new index to enforce the primary key, just use the
> existing unique index."
>
> I can't find any indication in the docs that SQL Server can do this,
> but thought I would check.
>
> Thanks,
>
> Bill