Transact-SQL Reference - Statements
This section provides a comprehensive reference for Transact-SQL (T-SQL) statements used in Microsoft SQL Server. T-SQL is an extension of SQL that adds procedural programming, local variables, character and time string functions, decision-making, and support for traditional programming constructs. Mastering T-SQL is essential for effectively managing and querying SQL Server databases.
Core T-SQL Statement Categories
T-SQL statements can be broadly categorized based on their function:
-
Data Definition Language (DDL) Statements
Used to define, alter, and drop database objects such as tables, views, indexes, and stored procedures.
-
Data Manipulation Language (DML) Statements
Used to retrieve, insert, update, and delete data in database tables.
-
Control-of-Flow Language Statements
Enable the creation of procedural logic within T-SQL, including conditional execution and loops.
-
Security Statements
Manage permissions, logins, and security contexts within SQL Server.
-
Transaction Control Language (TCL) Statements
Manage transactions, ensuring data consistency and integrity.
Key T-SQL Statements
Here are some of the most frequently used and important T-SQL statements:
-
CREATE TABLE
Defines a new table in the database.
-
SELECT
Retrieves rows from one or more tables.
-
INSERT INTO
Adds new rows to a table.
-
UPDATE
Modifies existing rows in a table.
-
DELETE FROM
Removes rows from a table.
-
ALTER TABLE
Modifies the structure of an existing table.
-
DROP TABLE
Deletes a table from the database.
-
BEGIN TRANSACTION
Starts a transaction.
-
COMMIT TRANSACTION
Saves all changes made during the current transaction.
-
ROLLBACK TRANSACTION
Discards all changes made during the current transaction.
-
IF...ELSE
Executes a set of T-SQL statements based on a specified condition.
-
WHILE
Executes a set of T-SQL statements as long as a specified condition is true.
Further Resources
Explore the links below for more detailed information and examples: