views:

58

answers:

1

I've made mistake creating clustered primary key on GUID column. There are many tables that reference that table with defined foreign keys. Table size is not significant.

I would like to convert it from clustered to non-clustered without manually dropping and recreating any foreign keys or even primary key constraint.

Is it possible to achieve that in MS SQL2005 and how if yes ?

Is it possible to achieve that ONLINE (without db down time) if yes ?

+1  A: 

You could try creating the unique nonclustered NC index first, then drop the clustered PK. The FK should recognise this other index (but might not: never tried it).

When you run ALTER TABLE to drop the clustered PK use the ONLINE option. However, it's only available in Enterprise edition.

ALTER TABLE Mytable DROP CONSTRAINT PK_Mytable WITH (ONLINE = ON)

You can't use ONLINE for the ADD CONSTRAINT bit.

Basically, your options are limited without blocking, or creating another table first and moving data over...

gbn
I wish I could get an answer without word "try" ...
alpav
@alpav: unfortunately, I'd probably just drop the lot, fix, recreate. And try to remember for next time :-) Try it with a 200 million row table: that's painful...
gbn
@gbn: FKs don't recognize another index. When I try to drop PK constraint even after creating another unique constraint and disabling foreign key constraint with ALTER TABLE Table2 NOCHECK CONSTRAINT FK_Table2_Table1, it complains that "The constraint 'PK_Table1' is being referenced by table 'Table2', foreign key constraint 'FK_Table2_Table1'. Only dropping FKs works.
alpav