Wednesday, March 21, 2012

Is it possible to create clustered index for multi tables within a SQL Server 2005 database with

Hi, all,

I am having up to serveral hundred tables within a SQL Server 2005 database, up to 200 of them are without any clustered index. Is it possible to create clustered indexes for all of them together in a same query? :)

Thanks a lot for any guidance and advices for that.

With best regards,

Yours sincerely,

Yes, it is possible with WHILE loop and dynamic SQL (with eithersp_executesql or EXEC statement) that calls CREATE INDEX. However, the tricky part is you have to specify the column(s) for each table to be included in the index in the CREATE INDEX statement. So if you have a way to programmatically get the table names and the index column(s) for each table, it is easy to do the rest.|||

Hi, Hugh Qu,

Thank you very much for your kind guidance and advices. Got the ideas, very appreciated.

With best regards,

Yours sincerely,

No comments:

Post a Comment