1. What is T-SQL? Why care?
Idea: T-SQL (Transact-SQL) is Microsoft SQL Server's flavor of SQL. It is still SQL, plus extra features (variables, control flow, error handling).
In Plain English
Think of SQL as the shared language for talking to relational databases. T-SQL is a dialect: same base grammar, a few local words. If you learn standard SQL concepts (tables, rows, SELECT) you are 80% there. T-SQL adds tools to write scripts and stored procedures.
Where Does It Run?
T-SQL runs on Microsoft SQL Server and Azure SQL Database. You send commands to the server; it sends back results or changes data.
Why Learn It?
- Read data: build reports, answer questions.
- Clean and shape data for apps and analytics.
- Automate tasks with stored procedures and scripts.
Core Mental Model
You describe what you want ("Give me these columns, only recent rows") and the server decides how to fetch it efficiently.
Placeholders for Examples
Example coming soon: a SELECT from a sample table.
Advanced Deep Dive ADVANCED
Batch vs Statement: SQL Server compiles execution plans per batch. Understanding batch boundaries (GO separators in tools) matters for variables and temporary objects.
ANSI vs T-SQL Extensions: T-SQL adds procedural constructs (DECLARE, WHILE), error handling (TRY...CATCH), table variables, and system stored procedures.
Set-Based Thinking: Favor operations on many rows at once over row-by-row loops. This impacts performance and concurrency.
Logical Processing Order: Although you write SELECT first, conceptually FROM and JOIN happen before WHERE, then GROUP BY, HAVING, SELECT list, ORDER BY. Knowing this prevents surprises with aliases and aggregates.
Execution Plans: SQL Server transforms your declarative intent into operators (Index Seek, Hash Join, Sort). Reading them early helps you avoid anti-patterns.