Sql Server Reindex Tables

During my attempt to shrink my database so that it would fit on my laptop (it was 20 gigs), I figured out that I needed to reindex all my tables.  Usually the format of your data and log files will follow this pattern – just replace the {DATABASE_NAME} with the name of your database.

DBCC SHRINKFILE ({DATABASE_NAME}_data,5)

DBCC SHRINKFILE (
{DATABASE_NAME}_log, 1);
BACKUP LOG
{DATABASE_NAME} WITH TRUNCATE_ONLY;
DBCC SHRINKFILE (
{DATABASE_NAME}_log, 1);

4 thoughts on “Sql Server Reindex Tables”

  1. You’ve got a bug in the DBCC line — you used @tablename when you should’ve only used @table. Otherwise works great. Thanks.

Leave a Reply

Your email address will not be published. Required fields are marked *