SQL Server Cheat Sheet
This SQL Server Cheat Sheet provides a compact overview of commonly used SQL statements, functions and administration commands for developers and DBAs. Whether for quick lookup, troubleshooting or learning purposes, this reference guide is designed to make working with SQL Server faster and more efficient.
Table of Contents
Command snippets
# create a test table t with 1 million rows
SELECT TOP (1000000) a2.* INTO t FROM sys.all_objects a1 CROSS JOIN sys.all_objects a2;
# update table stats
update statistics t;
# enable output of IO statistics and timing statistics
set statistics io on;
set statistics time on;
# Output SQL statistics without running them
set showplan_all on;
# activate SQL Server Agent (when SQL Server Agents shows: "Agent XPs disabled" in SSMS)
USE master;
GO
sp_configure 'show advanced options', 1;
RECONFIGURE;
GO
sp_configure 'Agent XPs', 1;
RECONFIGURE;
GO
# check logical and physical integrity of a database
dbcc checkdb('JBDB')
Useful Resources
- Stack Overflow Database backup files (for testing / 1.5 – 202 GB)

Leave a Reply