Microsoft Docs

Azure SQL Database Transact-SQL Reference

Transact-SQL Reference for Azure SQL Database

This documentation provides a comprehensive reference for the Transact-SQL (T-SQL) language as implemented in Azure SQL Database. T-SQL is Microsoft's proprietary extension of SQL that is used to manage and query data in SQL Server and Azure SQL Database.

Note: While Azure SQL Database is highly compatible with SQL Server, there may be minor differences in T-SQL syntax and features. Always refer to this specific documentation for the most accurate information.

Key Components of T-SQL Reference

Data Types

Understand the various data types available in Azure SQL Database, including numeric, character, date and time, spatial, and XML types. Each data type has specific characteristics and storage requirements.

-- Example: Declaring a variable with a specific data type
DECLARE @orderCount INT;
DECLARE @productName VARCHAR(100);
DECLARE @orderDate DATETIME2(7);

Explore all Data Types

DDL Statements (Data Definition Language)

Learn how to create, alter, and drop database objects such as tables, views, indexes, stored procedures, and functions using DDL statements like CREATE, ALTER, and DROP.

-- Example: Creating a simple table
CREATE TABLE Employees (
    EmployeeID INT PRIMARY KEY,
    FirstName VARCHAR(50) NOT NULL,
    LastName VARCHAR(50) NOT NULL,
    HireDate DATE
);

Learn more about DDL Statements

DML Statements (Data Manipulation Language)

Master the commands used to insert, update, delete, and retrieve data from your database. This includes SELECT, INSERT, UPDATE, and DELETE statements, along with clauses like WHERE, GROUP BY, and ORDER BY.

-- Example: Inserting data into a table
INSERT INTO Employees (EmployeeID, FirstName, LastName, HireDate)
VALUES (101, 'Jane', 'Doe', '2023-01-15');

-- Example: Selecting data
SELECT FirstName, LastName
FROM Employees
WHERE HireDate >= '2023-01-01';

Discover DML Statement Syntax

Functions

Utilize the built-in T-SQL functions for string manipulation, mathematical operations, date and time calculations, aggregate calculations, and more. This section also covers user-defined functions (UDFs).

-- Example: Using a string function
SELECT UPPER(FirstName) AS UpperFirstName
FROM Employees;

-- Example: Using an aggregate function
SELECT COUNT(*) AS TotalEmployees
FROM Employees;

Browse all T-SQL Functions

System Stored Procedures and Views

Access system-level information and perform administrative tasks using system stored procedures and system catalog views. These provide insights into database performance, configuration, and metadata.

Tip: Use system views like `sys.tables` and `sys.columns` to query metadata about your database objects.

Explore System Stored Procedures

Explore System Catalog Views

Warning: Be cautious when executing system stored procedures, as some can modify database settings or configurations. Always understand their purpose before execution.