question

sandy_1006 avatar image
sandy_1006 asked

Index Rebuild scipt for manually running the tables rebuild.

Hi Experts,

There are tables in our environment for example a,b,c,d,e,f,g,h,i

We are running

ALTER INDEX ALL ON [dbo].[a] REBUILD WITH (ONLINE = ON);

Manually copy paste on the ssms one by one , Once the index rebuild on table a finishes then we run on table b and when b finished we run c like that,

Can i write a loop where we run the index rebuild within a loop one by one table rebuild index.

Thanks.

rebuildsql 2014
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

1 Answer

·
JohnM avatar image
JohnM answered

Why not just download Ola's Index maintenance solution and put it in a job?

https://ola.hallengren.com/sql-server-index-and-statistics-maintenance.html

Is there a specific reason you are doing it manually?

1 comment
10 |1200

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

ThomasRushton avatar image ThomasRushton ♦♦ commented ·

Or, if you only need an index rebuild script, why not Michelle "@SQLFool" Ufford's script, available from https://github.com/MichelleUfford/sql-scripts/blob/master/indexes/dba_indexDefrag_sp.sql ?

0 Likes 0 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.