100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace

Microsoft SQL Server Cheat Sheet

Microsoft SQL Server Cheat Sheet

T-SQL essentials for Microsoft SQL Server covering DDL/DML, clustered vs nonclustered indexes, MERGE statements, and query plan analysis.

2 PagesIntermediateMar 2, 2026

T-SQL Basics

Connecting and browsing databases.

sql
-- Connect via sqlcmd-- sqlcmd -S localhost -U sa -P YourPasswordSELECT name FROM sys.databases;USE MyDb;GOSELECT TOP 10 * FROM Users;

DDL, DML & MERGE

Creating tables and upserting rows.

sql
CREATE TABLE Users (  Id INT IDENTITY(1,1) PRIMARY KEY,  Email NVARCHAR(255) NOT NULL UNIQUE,  CreatedAt DATETIME2 DEFAULT SYSUTCDATETIME());INSERT INTO Users (Email) VALUES ('a@b.com');MERGE INTO Users AS targetUSING (SELECT 1 AS Id, 'x@y.com' AS Email) AS srcON target.Id = src.IdWHEN MATCHED THEN UPDATE SET Email = src.EmailWHEN NOT MATCHED THEN INSERT (Email) VALUES (src.Email);

Indexes & Query Plans

Index types and inspecting IO cost.

sql
CREATE CLUSTERED INDEX IX_Users_Id ON Users(Id);CREATE NONCLUSTERED INDEX IX_Users_Email ON Users(Email);SET STATISTICS IO ON;SELECT * FROM Users WHERE Email = 'a@b.com';

Core Concepts

Terminology specific to SQL Server.

  • Clustered index- determines the physical row order on disk; only one per table
  • Nonclustered index- a separate structure with pointers back to the data row
  • IDENTITY(seed, increment)- auto-incrementing column, SQL Server's AUTO_INCREMENT equivalent
  • T-SQL- Microsoft's SQL dialect adding variables, TRY/CATCH, and control flow
  • Schema- a namespace within a database, e.g. dbo.Users
  • GO- a batch separator recognized by SSMS/sqlcmd, not part of T-SQL itself
Pro Tip

Use SET STATISTICS IO ON together with the actual (not estimated) execution plan to see real logical page reads — a query can look cheap in the estimated plan while doing far more work than expected.

Was this cheat sheet helpful?

Explore Topics

#MicrosoftSQLServer#MicrosoftSQLServerCheatSheet#Database#Intermediate#TSQLBasics#DDLDMLMERGE#IndexesQueryPlans#CoreConcepts#Databases#Git#CheatSheet#SkillVeris
Advertisement
Sri Hayavadhana Info-Tech

Professional Web Designing Services

  • Responsive Websites
  • E-commerce Solutions
  • SEO Friendly Design
  • Fast & Secure
  • Support & Maintenance
Get a Free Quote

Share this Cheat Sheet