SQL Server T-SQL Statements

Comprehensive documentation for Transact-SQL statement syntax and usage.

Data Definition Language (DDL)

CREATE

Creates database objects such as tables, views, or stored procedures.

ALTER

Modifies existing database objects.

DROP

Deletes database objects.

TRUNCATE

Removes all rows from a table quickly.

Data Manipulation Language (DML)

SELECT

Retrieves data from one or more tables.

INSERT

Adds new rows of data to a table.

UPDATE

Modifies existing data in a table.

DELETE

Removes rows from a table.

Control Flow Language

IF...ELSE

Executes a block of statements conditionally.

WHILE

Executes a block of statements repeatedly as long as a condition is true.

BEGIN...END

Groups multiple Transact-SQL statements into a logical block.

WAITFOR

Suspends batch execution until a specified time or time interval.

Transaction Control Language (TCL)

BEGIN TRANSACTION

Starts a transaction.

COMMIT TRANSACTION

Saves all changes made during the current transaction.

ROLLBACK TRANSACTION

Reverts all changes made during the current transaction.

SAVE TRANSACTION

Sets a point within a transaction to which you can later roll back.

Error Handling

TRY...CATCH

Provides structured error handling for Transact-SQL code blocks.

RAISERROR

Generates a user-defined error message and returns it to the client.

Other Statements

USE

Specifies the default database context for subsequent statements.

SET

Changes session-level settings that affect Transact-SQL statement execution.

DECLARE

Declares a variable, cursor, or temporary table.