SQL T-SQL Syntax - Documentation

This page provides a concise overview of the syntax and essential concepts for the T-SQL programming language.

This is a fundamental example of how to define a stored procedure.

Introduction

T-SQL (Transact-SQL) is the standard SQL language used by Microsoft SQL Server. It provides a way to create database objects and perform various tasks with the SQL Server database.

Let's start with a simple example: creating a stored procedure to greet a user.

Stating the procedure's name:

CREATE PROCEDURE GetGreeting( @Greeting VARCHAR(50) ) AS BEGIN SELECT 'Hello, ' + @Greeting + '!'; END; GO

Explanation: This is the beginning of a stored procedure definition. It includes: - CREATE PROCEDURE GetGreeting: Defines a new stored procedure named "GetGreeting." - `@Greeting VARCHAR(50)`: Defines a parameter named "Greeting" which accepts a string (VARCHAR) with a maximum length of 50 characters. The parameter is used to receive data from the user.

- `AS BEGIN ... END;` : This defines the code block that will be executed when the stored procedure is called.

Execution: When you run this procedure, it will: 1. Receive the value of the 'Greeting' parameter. 2. Use the `SELECT` statement to output a greeting message.

Important Considerations:

This is a basic example. Stored procedures can perform complex operations, manage data, and interact with other database objects.

Further Learning: Refer to the official Microsoft documentation for more in-depth information.

Further examples are available in the documentation section.

Link: [https://learn.microsoft.com/en-us/sql/t-sql/](https://learn.microsoft.com/en-us/sql/t-sql)