SQL Server & T-SQL
What it is & where it is used
Microsoft SQL Server is a relational database management system (RDBMS). T-SQL (Transact-SQL) is Microsoft's extension of ANSI SQL with variables, control flow, error handling, stored procedures and more.
The SQL Server family:
| Component | Purpose |
|---|---|
| Database Engine | Stores and queries data (OLTP) |
| SSIS (Integration Services) | ETL — see the SSIS course |
| SSRS (Reporting Services) / Power BI Report Server | Paginated reports |
| SSAS (Analysis Services) | OLAP cubes, tabular models |
| SQL Server Agent | Job scheduling |
| Azure SQL Database / Managed Instance | PaaS versions in Azure |
Editions: Enterprise, Standard, Developer (free, full features, non-production), Express (free, limited), and Azure SQL.
SQL statement categories:
| Category | Statements |
|---|---|
| DDL (Definition) | CREATE, ALTER, DROP, TRUNCATE |
| DML (Manipulation) | SELECT, INSERT, UPDATE, DELETE, MERGE |
| DCL (Control) | GRANT, REVOKE, DENY |
| TCL (Transaction) | BEGIN TRAN, COMMIT, ROLLBACK, SAVE TRAN |
Versions & history
| Version | Year | Highlights |
|---|---|---|
| SQL Server 2005 | 2005 | CTEs, ROW_NUMBER/ranking functions, TRY...CATCH, SSIS replaces DTS, CLR integration |
| 2008 / 2008 R2 | 2008/2010 | MERGE, DATE/TIME types, table-valued parameters, filtered indexes |
| 2012 | 2012 | OFFSET/FETCH, LAG/LEAD, window frames, SEQUENCE, THROW, TRY_CONVERT, IIF, Always On Availability Groups, columnstore (read-only) |
| 2014 | 2014 | In-Memory OLTP (Hekaton), updatable clustered columnstore |
| 2016 | 2016 | Query Store, temporal tables, JSON functions, Row-Level Security, Dynamic Data Masking, Always Encrypted, STRING_SPLIT |
| 2017 | 2017 | Linux support, STRING_AGG, TRIM, CONCAT_WS, graph tables, adaptive query processing |
| 2019 | 2019 | Intelligent Query Processing (scalar UDF inlining, table variable deferred compilation), Accelerated Database Recovery, UTF-8 |
| 2022 | 2022 | Azure Synapse Link, ledger tables, GREATEST/LEAST, DATE_BUCKET, GENERATE_SERIES, IS [NOT] DISTINCT FROM, parameter-sensitive plan optimisation |
| 2025 | 2025 | AI-ready: native vector data type and vector search, native JSON type, regular expression functions (REGEXP_LIKE etc.), optimized locking, Fabric mirroring |
Lifecycle
How SQL Server executes a query:
- Parse — syntax check, build a parse tree.
- Bind (algebrize) — resolve names, types, permissions.
- Optimise — the cost-based query optimizer uses statistics to choose an execution plan (join types, index seeks vs scans, parallelism).
- Plan cache — plan stored for reuse (parameterised queries reuse plans).
- Execute — the storage engine reads pages from the buffer pool (memory) or disk, acquiring locks/latches.
- Return results to the client.
Logical query processing order (not the written order):
FROM → ON → JOIN → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → TOP/OFFSET-FETCH
That's why you can't use a SELECT alias in WHERE, but you can in ORDER BY.
Transaction lifecycle: BEGIN TRAN → statements write to the transaction log first (write-ahead logging) → COMMIT (durable once the log is hardened) or ROLLBACK (undo using the log). Checkpoints write dirty pages to data files; recovery replays/undoes the log after a crash.
Database development lifecycle: requirements → conceptual model (ER diagram) → logical design (normalisation) → physical design (types, indexes, partitions) → implementation (DDL scripts/migrations) → testing → deployment (DACPAC/scripts) → monitoring and tuning → maintenance (backups, index/statistics maintenance).
Tools used to develop
| Tool | Use |
|---|---|
| SQL Server Management Studio (SSMS 21) | Main admin/dev IDE: queries, execution plans, Agent, backups |
| VS Code + MSSQL extension | Cross-platform editor (Azure Data Studio retired Feb 2026) |
| SQL Server Data Tools (SSDT) / SQL database projects | Schema as code, DACPAC deployments |
sqlcmd, bcp | Command-line scripts and bulk copy |
| SQL Server Profiler / Extended Events | Tracing (Profiler is deprecated; prefer XEvents) |
| Query Store | Plan history, regressed queries, forcing plans |
| Database Engine Tuning Advisor | Index suggestions |
| SQL Server Agent | Scheduled jobs |
| sp_WhoIsActive, sp_Blitz (First Responder Kit) | Free community diagnostic scripts |
| Redgate SQL Prompt / SQL Compare, dbForge | Productivity and schema compare |
| Flyway, DbUp, EF migrations | Database migrations |