T-SQL (Transact-SQL)
T-SQL is the dialect of Microsoft SQL Server that is used for interacting with the database. It's a procedural extension of the SQL standard and provides a rich set of features for data manipulation, querying, and control.
Key Features
- Procedural Programming: T-SQL allows you to write code that executes a series of steps to accomplish a task.
- Control Structures: Includes IF-THEN-ELSE, WHILE, and looping constructs.
- Data Types: Extensive support for various data types, including numeric, string, date/time, and binary data.
- Stored Procedures: Reusable blocks of code that can be executed as a unit.
- Functions: Built-in and user-defined functions for performing calculations and data transformations.
Example Code
-- Simple SELECT statement
SELECT * FROM Customers;
-- Example of a stored procedure
CREATE PROCEDURE GetCustomerByID
(
@CustomerID INT
)
AS
BEGIN
SELECT * FROM Customers WHERE CustomerID = @CustomerID;
END;