Managing Indexes with T-SQL

One of the T-SQL features available with SQL Server 2008 is the ALTER INDEX statement. This statement simplifies many of the tasks associated with managing indexes. Index operations such as index rebuilds and changes to fill factor that were previously handled with DBCC commands are now available via the ALTER INDEX statement. The basic syntax for ALTER INDEX is as follows:

image

Let’s look at a few examples that demonstrate the power of the ALTER INDEX statement. The first example simply rebuilds the primary key index on the Production.Product table:

ALTER INDEX [PK_Product_ProductID] ON [Production].[Product] REBUILD

Get Microsoft® SQL Server 2008 R2 Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.