How to Maintain a Microsoft SQL Server 2008 Database
- 1). Open a connection to the database using either a command prompt or the SQL Server Management Studio, or SSMS.
- 2). Shrink the size of an individual files by typing "dbcc shrink file" followed by the file name of the file to shrink. You can optionally enter the size to shrink it to.
- 3). Shrink the size of an entire database, including both the data files and transaction log, by typing "dbcc shrinkdatabase" followed by the database name.
- 4). Type "dbcc cleantable," followed by the database and table name, to reduce empty space in a table or view that has had significant size reductions.
- 1). Clear buffers used by typing "dbcc dropcleanbuffers." This allows you to test how queries would execute after a server restart.
- 2). Remove stale stored procedure cache information by typing "dbcc freeproccache," followed by the plan handle, SQL handle or pool name of the item to be cleared. This will cause the stored procedure to recompile the next time it is run.
- 3). Correct row or page count issues by typing "dbcc updateusage" to update statistics. This command must be followed by either the database, table or index name to update.
Managing Files
Other Maintenance Tasks
Source...