Category Archives: MS SQL Server

How to put a database into Single User Mode with T-SQL

You can easily put a database into or take it out of single user mode with the following T-SQL: ALTER DATABASE  [MyDatabase] SET SINGLE_USER WITH NO_WAIT GO ALTER DATABASE  [MyDatabase] SET MULTI_USER WITH NO_WAIT GO

Posted in MS SQL Server | Leave a comment

Time Your T-SQL Queries

Here’s a quick way to get some timing statistics on your T-SQL: DBCC FREEPROCCACHE GO DBCC DROPCLEANBUFFERS GO SET STATISTICS TIME ON GO — Insert your query here SET STATISTICS TIME OFF GO After you run the statements in query … Continue reading

Posted in MS SQL Server | Leave a comment

How to Shrink Your Database Transaction Log

How to Shrink Your Database Transaction Log If you have noticed that your transaction log on your SQL Server database has grown incredibly large after a long transactional process, you can try this to shrink it back down: DBCC SHRINKFILE(mydatabase_log, … Continue reading

Posted in MS SQL Server | Leave a comment

Force a named pipes connection

To force a named pipes connection to your database, prepend the name in your connection string with “np:”. E.g.

Posted in C#, MS SQL Server | Leave a comment