Introduction to T-SQL
T-SQL (Transact-SQL) is Microsoft's extension of SQL used in SQL Server and Azure SQL Database, adding procedural programming features like variables, loops, and error handling on top of standard SQL.
SQL vs T-SQL
Standard SQL (Structured Query Language) lets you query and manipulate relational data with commands like SELECT, INSERT, and UPDATE. T-SQL builds on this foundation with Microsoft-specific extensions — variables, control-of-flow statements, stored procedures, and built-in functions — that turn SQL from a purely declarative query language into something closer to a full programming environment for the database.
T-SQL runs on Microsoft SQL Server and Azure SQL Database, and is one of the most widely used database skills in corporate and enterprise environments worldwide.
A First Query
Almost every T-SQL statement you write revolves around tables — structured collections of rows and columns. Here's a first look at retrieving data from one.
SELECT FirstName, LastName, Email
FROM Customers;
Common Mistakes
- Assuming all SQL dialects are identical — T-SQL, MySQL, and PostgreSQL each have their own extensions and quirks.
- Forgetting the semicolon at the end of statements, which SQL Server tolerates for single statements but is required by the standard and good practice for clarity.
- Confusing a database (a container) with a table (a structured collection of data inside it).
- Not knowing which database you're connected to before running a query, especially in an environment with multiple databases.
Professional Tip
SQL keywords like SELECT, FROM, and WHERE are traditionally written in uppercase, while table and column names are written as they were created. This isn't required by the engine, but it makes queries dramatically easier to read at a glance.
Your Turn
Write a SELECT statement (using placeholder table and column names) to retrieve a product's name and price from a hypothetical Products table.
Mini Quiz
What does T-SQL add on top of standard SQL?