Wednesday, October 23, 2013

SQL Azure required clustered Index

A

After deploying my database to Azure, I used the Management portal to insert some rows of data, and encountered the following error.

Tables without a clustered index are not supported in this version of SQL Server. Please create a clustered index and try again.

I found the following SO article that shows how to add a clustered index to a single table. So, I wrote the following script to generate the ddl to create a clustered index on every table.

select 'CREATE CLUSTERED INDEX CX_' + name + '_Id ON ' + name + ' (Id)' from sysobjects where xtype = 'U'

This generates output like this

CREATE CLUSTERED INDEX CX_Error_Id ON Error (Id)

CREATE CLUSTERED INDEX CX_Tournament_Id ON Tournament (Id)

CREATE CLUSTERED INDEX CX_User_Id ON User (Id)

After taking the output and running this on my SQL Azure database, now, I can successfully insert records into each table.