How to configure SQL Server tempdb for optimal performance

SQL Server tempdb is a database in SQL Server which is used to store temporary user objects and internal objects. Because the tempdb is used a lot by SQL Server it is important for the performance to configure it correctly. Tempdb is only using one data file by default. Multiple data files can improve the [...]

How to make your SQL Server index faster by updating statistics

The query optimizer in SQL Server uses statistics. The data in statistics is used to create the query plans that improve query performance. If the data in the statistics is better the queries will perform faster. To ensure the queries will perform as fast as possible it is important to update the statistics. You can [...]

How to speed up SQL Server log file by reducing number of virtual log file

Background: A log file records all the changes that occur in a SQL Server database. This log file contains multiple virtual log files(VLFs) these are used to manage space reuse. If SQL Server needs more space to store this information the log file will increase by its Autogrowth size. Increasing the size of the log [...]

How to shrink logfile in SQL Server 2005/2008

Background: A log file records all the changes that occur in a SQL Server database. Normally the log file doesn’t grow but reuses inactive portions of the log. If the Recovery model of the database is set to Full however the log file can grow very big if you forget to back up the log [...]

How to defragment indexes using script in SQL Server 2005/2008 R2

Background: When a query is executed on a database, indexes are used to physically locate the data on disk. Due to frequent insert, update and delete statements this data can become fragmented. This is a serious performance issue. To mitigate this schedeule this script in a SQL Agent Job to frequently defragment you indexes. Steps: [...]

How to script logins from user database in SQL Server 2005/2008 R2

Background: A database contains database users that are mapped to Logins (SQL or Windows) via a SID. When you want to move a database to an other server it is neccessary to also move the logins that are being used by the database. Without this you will end up with orphaned users. Steps: 1. Create [...]

How to move a user database in SQL Server 2005/2008 R2

Background: A user database is attached to a certain SQL Server instance and consists of at least two files: mdf (data file) and ldf (log file). To move a database it needs to be detached from the SQL Server instance so the files are released. After detachment the files can be moved to an other [...]

How to restore master database in SQL Server 2005/2008 R2

Background: The master database holds all Instance settings, logins and registers which databases are connected to the server. If the master database gets corrupted SQL Server stops working and the service can’t be started. In this scenario the master database first has to be rebuild before a restore is possible. See article: How to rebuild [...]

How to move temp db in SQL Server 2005/2008 R2

Background: All temporary results from stored procedures of all databases are temporary stored in the tempdb. Because of its central part in the execution of T-SQL statements it can easily become a performance bottlekneck. To mitigate this it is best to move the tempdb to a fast drive instead of its default location in c:\. [...]