iefpw
iefpw

Reputation: 7042

Alter clustered index column

I have a clustered index on a table indexing on the text column. I want to switch that column with a different column like ID, how do I alter the index?

I can't drop and recreate because this is running on Azure and the table needs to have clustered index all the time.

The SQL command and the syntax for changing index columns in an index.

alter index ?

Upvotes: 10

Views: 21043

Answers (2)

Ben Thul
Ben Thul

Reputation: 32687

Try this:

create clustered index [your_index_name] 
on [your_table] 
   ([ID]) 
with (drop_existing = on)

Upvotes: 18

marc_s
marc_s

Reputation: 754348

You cannot alter a clustered index.

The only option is to drop it and re-create it with the new column.

In your case, you'll probably have to re-create the table with the new clustered index on ID and then copy the data over.

Upvotes: 7

Related Questions