MSDN Documentation

Microsoft Developer Network

Transact-SQL (T-SQL) Language Reference

This section provides a comprehensive reference for the Transact-SQL (T-SQL) language used with Microsoft SQL Server and Azure SQL Database.

Introduction to T-SQL

Transact-SQL (T-SQL) is Microsoft's proprietary extension of SQL (Structured Query Language) that is used for managing and manipulating databases in Microsoft SQL Server and Azure SQL Database.

Language Overview

T-SQL combines standard SQL with procedural programming constructs, local variables, and support for character, date, time, XML, and spatial data. It is a powerful language for:

T-SQL Statements

T-SQL statements are the fundamental building blocks for interacting with a database. They can be categorized into several types:

Data Definition Language (DDL) Statements

DDL statements are used to define, alter, and drop database objects.

Data Manipulation Language (DML) Statements

DML statements are used to retrieve, insert, update, and delete data in database tables.

-- Example: Selecting data
SELECT column1, column2
FROM your_table
WHERE condition;

Data Control Language (DCL) Statements

DCL statements are used to manage permissions and access to database objects.

T-SQL Functions

Functions return a scalar value, a table, or a set of values. They are crucial for data processing and manipulation.

Aggregate Functions

Aggregate functions perform a calculation on a set of values and return a single value.

Scalar Functions

Scalar functions return a single value based on the input values.

Table-Valued Functions (TVFs)

TVFs return a table result, which can be used in the FROM clause of queries.

T-SQL Operators

Operators are used in expressions to perform operations on values. These include:

T-SQL Data Types

T-SQL supports a wide range of data types for storing different kinds of information:

T-SQL Reserved Words

Certain words are reserved in T-SQL and cannot be used as identifiers (e.g., table names, column names) unless they are delimited by square brackets ([...]) or double quotes ("...").

Examples include: SELECT, FROM, WHERE, INSERT, UPDATE, DELETE, CREATE, ALTER, DROP, TABLE, INDEX, VIEW, FUNCTION, PROCEDURE.

For detailed syntax and examples of each statement, function, and operator, please refer to the specific documentation pages.