Rebuild Index in SQL Only On One Table
27,762
Solution 1
There's a difference between REORGANIZE and REBUILD. See this blog post for details.
If you truly want to REBUILD, and you want to do it for ALL indexes on a given table, then the command would be (straight from the official docs that npe pointed you at):
ALTER INDEX ALL ON mySchema.myTable REBUILD
Solution 2
Try this:
ALTER INDEX indexName ON mySchema.myTable REORGANIZE;
For more instructions see the official docs. The link points to SQL Server 2014 docs, but the syntax should work on 2005 and 2008 as well.
Author by
E. Peterson
Updated on July 29, 2020Comments
-
E. Peterson almost 4 years
Looking to create a SQL query that rebuilds indexes in SQL on only one table within my database. Can anyone point me in the right direction. Someone earlier suggested Ola Hallengren SQL maintenance, but I think that is too robust for what I'm after.