A second solution to my size of index table puzzle: Rama Mathanmohan’s query sums used pages from sys.allocation_units to give each index size in KB.
Finding the First Monday of Every Month in T-SQL
Calculate the first Monday without DATEFIRST, list a full year, find nth and last weekdays, and reuse the rules in an inline table function.
SQL SERVER – Get Latest SQL Query for Sessions – DMV
Want the latest SQL query for sessions on your server? Join sys.dm_exec_connections with sys.dm_exec_sql_text using most_recent_sql_handle.
SQL SERVER – SHRINKFILE and TRUNCATE Log File in SQL Server 2008
A reader’s job failed after upgrading to SQL Server 2008 because TRUNCATE_ONLY is gone. My notes on SHRINKFILE and TRUNCATE Log File, and what to watch for.
SQL SERVER – Attach mdf file without ldf file in Database
A friend sent me only his mdf file instead of a backup of the database. Here is how to attach mdf file without ldf file and let SQL Server build a new log.
SQL SERVER – T-SQL Script to Take Database Offline – Take Database Online
A reader asked how to bring a database back online. This short T-SQL script will take database offline with ROLLBACK IMMEDIATE and then online again.
SQL SERVER – Update Statistics are Sampled By Default
A reader asked if statistics are sampled by default. They are, and a one million row test table proves it. You can set the rate up to 100%.







