Guides — 36 for SQL Server

SQL Server guides

Everything we've written about SQL Server: connections, SQL patterns, imports, clients, and comparisons.

01 — Connect & How-To

Connect & How-To

Connect & How-ToSQL Server

How to Connect to SQL Server from Rust

Connect to Microsoft SQL Server from Rust with tiberius, bb8/deadpool pooling, or ODBC. Working code for connections, @P1 parameters, TLS encryption levels, named instances via SQL Browser, and the sqlx-removed-MSSQL trap.

9 min read
Connect & How-ToSQL Server

SQL Server Indexes Explained

Clustered vs nonclustered indexes, included columns, key lookups, filtered indexes, and columnstore, with execution plan checks to verify indexes are used.

8 min read
Connect & How-ToSQL Server

Working with JSON in SQL Server

A practical guide to T-SQL JSON functions: JSON_VALUE, JSON_QUERY, OPENJSON, FOR JSON, JSON_MODIFY, plus the native json type and JSON indexes in SQL Server 2025.

8 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from Ruby

Connect to Microsoft SQL Server from Ruby with tiny_tds and FreeTDS, plus Sequel and ActiveRecord. Working code for connections, parameterized queries, the OUTPUT clause for generated keys, TLS/encryption on FreeTDS, named instances, and the errors you actually hit.

8 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from PHP

Connect to Microsoft SQL Server from PHP with the official sqlsrv and pdo_sqlsrv drivers: ODBC Driver 18, the Encrypt-defaults-on TLS trap, prepared statements, transactions, the OUTPUT clause for generated keys, and the errors you actually hit.

7 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from C# (.NET)

Connect to Microsoft SQL Server from C# with Microsoft.Data.SqlClient: ADO.NET basics, async queries, parameters, the Encrypt-by-default TLS change that breaks local connections, pooling, Dapper and EF Core, and the errors you actually hit.

8 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from Java

Connect to Microsoft SQL Server from Java with the official mssql-jdbc driver: JDBC URL, the encrypt-by-default TLS change that breaks local connections, HikariCP pooling, named instances, integrated auth, and the errors you actually hit.

8 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from Go

Connect to Microsoft SQL Server from Go with the official microsoft/go-mssqldb driver. Working code for the URL DSN, @p1 named parameters, the LastInsertId trap, the encrypt default, named instances, Azure AD auth, and connection pooling.

8 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from Node.js

Connect to Microsoft SQL Server from Node.js using the mssql package over the Tedious driver. Working code for connection pools, the encrypt/trustServerCertificate trap, Azure AD auth, and parameterized queries.

3 min read
Connect & How-ToSQL Server

How to Connect to SQL Server from Python

Connect to Microsoft SQL Server from Python with pyodbc, the new official mssql-python driver, or pymssql. Working code, the ODBC Driver 18 encryption trap, Linux setup, and which driver to pick in 2026.

7 min read
02 — SQL How-To

SQL How-To

SQL How-ToSQL Server

Splitting Strings and Querying JSON Arrays in SQL Server

How to split delimited strings into rows with STRING_SPLIT and OPENJSON, query JSON arrays stored in columns, and aggregate rows back into strings or arrays with STRING_AGG and JSON_ARRAYAGG.

7 min read
SQL How-ToSQL Server

IDENTITY vs Sequences in SQL Server: Auto-Generated Keys Done Right

T-SQL IDENTITY columns and SEQUENCE objects compared. SCOPE_IDENTITY vs @@IDENTITY vs OUTPUT INSERTED, the identity-cache gap-of-1000 after restarts, IDENTITY_INSERT, DBCC CHECKIDENT reseeding, CREATE SEQUENCE, NEXT VALUE FOR restrictions, and when to use which.

7 min read
SQL How-ToSQL Server

Stored Procedures in SQL Server: CREATE PROCEDURE, Parameters, and the Traps

T-SQL stored procedures explained. CREATE OR ALTER, IN/OUTPUT parameters, table-valued parameters, return codes vs OUTPUT vs result sets, SET NOCOUNT ON, parameter sniffing and its fixes, the sp_ prefix trap, error handling with TRY/CATCH and THROW.

8 min read
SQL How-ToSQL Server

Table Partitioning in SQL Server: Partition Functions, Schemes, and Switching

How table partitioning works in SQL Server. Covers partition functions and schemes, RANGE LEFT vs RIGHT, partition elimination, aligned indexes, SWITCH, sliding windows, and TRUNCATE WITH PARTITIONS.

7 min read
SQL How-ToSQL Server

Triggers in SQL Server: AFTER, INSTEAD OF, and the inserted/deleted Tables

How DML triggers work in SQL Server. Covers AFTER and INSTEAD OF triggers, the inserted and deleted virtual tables, the per-statement firing model, multi-row safety, nesting and recursion, and when not to use triggers at all.

7 min read
SQL How-ToSQL Server

Reading SQL Server Execution Plans: Estimated vs Actual, Operators, and Warnings

How to read T-SQL execution plans. Covers estimated vs actual plans, SET STATISTICS XML, scan vs seek, key lookups, spills and implicit-conversion warnings, cardinality estimates, sys.dm_exec_query_plan_stats, and Query Store.

6 min read
SQL How-ToSQL Server

Temp Tables vs Table Variables in SQL Server: When Each One Wins

T-SQL #temp tables vs @table variables compared. Covers statistics and cardinality estimates, the 1-row legacy estimate and 2019 deferred compilation, transactions and rollback behavior, parallelism limits, indexes, recompiles, and a decision guide.

6 min read
SQL How-ToSQL Server

Upsert in SQL Server: MERGE, UPDATE-then-INSERT, and the Race Conditions

How to upsert in SQL Server. Covers the MERGE statement (all three WHEN clauses, the HOLDLOCK race condition, the honest state of its bug list), the UPDATE-then-INSERT pattern, and which to use.

6 min read
SQL How-ToSQL Server

Transactions in SQL Server: BEGIN TRAN, XACT_ABORT, and Isolation Levels

How transactions work in SQL Server. Covers BEGIN/COMMIT/ROLLBACK, the XACT_ABORT trap, nested transaction behavior, savepoints, all five isolation levels, RCSI vs SNAPSHOT, and deadlock handling.

7 min read
SQL How-ToSQL Server

SQL Server Subqueries: Scalar, Correlated, EXISTS vs IN, and Derived Tables

T-SQL subqueries explained. Covers scalar subqueries and error 512, IN vs EXISTS, the NOT IN NULL trap, correlated subqueries, derived tables and the mandatory alias, ANY/ALL/SOME, and when to rewrite a correlated subquery as APPLY.

8 min read
SQL How-ToSQL Server

SQL Server Views and Indexed Views: CREATE VIEW, SCHEMABINDING, NOEXPAND

T-SQL views explained. Covers CREATE OR ALTER VIEW, updatable views and WITH CHECK OPTION, the SELECT * schema-drift trap and sp_refreshview, ORDER BY restrictions, plus indexed views: SCHEMABINDING, COUNT_BIG, the definition restrictions, and the NOEXPAND hint on non-Enterprise editions.

8 min read
SQL How-ToSQL Server

SQL Server Aggregate Functions: COUNT, SUM, AVG, and GROUP BY Traps

T-SQL aggregate functions explained. Covers COUNT(*) vs COUNT(column), the SUM int overflow error, the AVG integer division trap, NULL elimination, HAVING vs WHERE, ROLLUP and GROUPING SETS, conditional aggregation without FILTER, and APPROX_COUNT_DISTINCT.

6 min read
SQL How-ToSQL Server

SQL Server String Functions: CONCAT, STRING_AGG, STRING_SPLIT, and the Traps

T-SQL string functions explained. Covers CONCAT vs the + operator NULL trap, LEN vs DATALENGTH, CHARINDEX and PATINDEX, STUFF, TRIM, STRING_SPLIT with ordinal, STRING_AGG truncation, collation case sensitivity, and the 2025 regex functions.

6 min read
SQL How-ToSQL Server

SQL Server Date Functions: DATEADD, DATEDIFF, DATETRUNC, and Formatting

How to work with dates in SQL Server. Covers datetime2 vs datetime, GETDATE vs SYSDATETIME, DATEDIFF boundary counting, DATETRUNC and DATE_BUCKET (2022), AT TIME ZONE, FORMAT vs CONVERT, and sargable date filters.

6 min read
SQL How-ToSQL Server

Full-Text Search in SQL Server: CONTAINS, FREETEXT, and Ranking

How to set up and query full-text search in SQL Server. Covers full-text indexes and catalogs, CONTAINS vs FREETEXT, CONTAINSTABLE ranking, prefix-only wildcards, the stoplist trap, and async population.

7 min read
SQL How-ToSQL Server

SQL Server Joins: INNER, OUTER, CROSS APPLY, and Anti-Joins

How joins work in SQL Server. Covers INNER, LEFT, RIGHT, FULL, and CROSS joins, the ON vs WHERE trap on outer joins, anti-join patterns (NOT EXISTS vs NOT IN), CROSS APPLY and OUTER APPLY, and join hints.

9 min read
SQL How-ToSQL Server

Pivot Tables in SQL Server: PIVOT, UNPIVOT, and Dynamic Columns

How to pivot rows into columns in SQL Server. Covers the native PIVOT operator, conditional aggregation with CASE, UNPIVOT and its NULL-dropping behavior, CROSS APPLY VALUES, and dynamic pivots with sp_executesql.

6 min read
SQL How-ToSQL Server

CTEs in SQL Server: WITH Syntax, Recursive Queries, and MAXRECURSION

How to use common table expressions in SQL Server. Covers WITH syntax, chaining CTEs, recursive CTEs for hierarchies, the MAXRECURSION 100 default, the semicolon quirk, and CTE vs temp table.

6 min read
SQL How-ToSQL Server

SQL Server Window Functions: ROW_NUMBER, RANK, LAG, Running Totals

How to use window functions in SQL Server with OVER, PARTITION BY, and frame clauses. Covers ROW_NUMBER, RANK, LAG/LEAD, the RANGE default gotcha, and the 2022 WINDOW clause and IGNORE NULLS.

6 min read
← All guides