Cursor for tables

  • I have stored alter commands in table for reindexing.

    How should I execute them one by one using cursor or any other method.

    Below are the commands stored in table.

    alter index PK_Customer_CustomerID On SalesLT.Customer REORGANIZE

    alter index PK_Product_ProductID On SalesLT.Product REORGANIZE

  • A cursor is fine. You'll end up calling sp_executesql for each row which will make the overhead of the cursor insignificant.

    Though, for index maintenance, don't reinvent the wheel, use ola hallengren's scripts.

  • Thanks

    Its worked !

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply