Page cover

Ultimate SQL Server Cheat Sheet

This ultimate SQL Server cheat sheet is designed to be a quick reference guide for database administrators, developers, and data analysts. It covers fundamental commands, concepts, and best-practices.

Getting Started

Connecting to SQL Server

  • Connect using SQL Server Management Studio (SSMS):

    • Open SSMS

    • Enter server name

    • Choose authentication mode (Windows/SQL Server)

    • Click 'Connect'

Sample Data

  • Table: Employees

-- create table
CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY IDENTITY(1,1),
    Name VARCHAR(100) NOT NULL,
    Age INT,
    Department VARCHAR(50),
    Salary DECIMAL(10,2),
    Email VARCHAR(100) NULL
);
-- insert sample data
INSERT INTO Employees (Name, Age, Department, Salary, Email)
VALUES 
('John Doe', 30, 'IT', 60000.00, '[email protected]'),
('Jane Smith', 28, 'HR', 55000.00, '[email protected]'),
('Alice Johnson', 35, 'Finance', 75000.00, '[email protected]'),
('Bob Williams', 40, 'IT', 80000.00, '[email protected]'),
('Charlie Brown', 27, 'Marketing', 50000.00, '[email protected]');
  • Table: Departments

  • Table: Employee_Audit

Basic Commands

CRUD Operations

Filtering & Sorting

Joins

Aggregations & Grouping

Subqueries

Common Table Expressions (CTEs)

Window Functions

Indexing

Stored Procedures & Functions

Transactions

Triggers

Error Handling

Security & User Management

Performance Tuning

Last updated

Was this helpful?