Microsoft SQL Server Documentation

Transact-SQL Syntax Conventions

This document outlines the syntax conventions used in the Transact-SQL (T-SQL) documentation for Microsoft SQL Server. Understanding these conventions will help you correctly interpret T-SQL syntax examples and write your own T-SQL code.

General Conventions

  • SQL keywords are displayed in uppercase. For example: SELECT, INSERT, UPDATE, DELETE.
  • Syntax elements that are part of the SQL language itself (keywords, identifiers, data types) are displayed in plain text.
  • Parameters or variables that you must supply are displayed in italicized text. For example: database_name, table_name.
  • Optional syntax elements are enclosed in square brackets ([ ]). For example: CREATE PROCEDURE [ schema_name. ] procedure_name.
  • If an optional element can be repeated, an ellipsis (...) is used after the square brackets. For example: [ column_name [ ,...n ] ].
  • Required elements that have alternative choices are displayed in curly braces ({ }) with vertical bars (|) separating the choices. The first choice is the default if no other choice is specified. For example: { READ UNCOMMITTED | READ COMMITTED | REPEATABLE READ | SERIALIZABLE }.
  • When optional elements have alternative choices, the choices are enclosed in curly braces ({ }) and separated by vertical bars (|). The option outside the curly braces is the default. For example: SET SHOWPLAN_ALL { ON | OFF }.
  • The sequence :: denotes a static member.

Code Examples

Code examples are provided to illustrate the usage of T-SQL statements. These examples follow the conventions outlined above.

Example: CREATE TABLE Statement

CREATE TABLE [ schema_name. ] table_name
(
    column_name data_type [ ( length ) ] [ COLLATE collation_name ] [ column_constraint ] [ ...n ]
)
[ table_constraint ] [ ,...n ]

Commonly Used Symbols

Symbol Description
[ ] Indicates optional syntax.
{ } Indicates a choice between options.
| Separates choices within curly braces.
... Indicates that the preceding element can be repeated.
italic text Represents user-supplied values or parameters.
UPPERCASE Represents SQL Server keywords.

Specific Elements

  • Keywords: Reserved words in T-SQL that have a specific meaning and function. These are typically written in uppercase.
  • Identifiers: Names of database objects such as tables, columns, procedures, etc. These can be enclosed in square brackets ([ ]) if they contain special characters or are reserved words.
  • Data Types: Specify the type of data a column can hold (e.g., INT, VARCHAR, DATETIME).
  • Constraints: Rules applied to data in a table to ensure data integrity (e.g., PRIMARY KEY, FOREIGN KEY, NOT NULL).

By adhering to these conventions, you can effectively navigate and utilize the T-SQL documentation to master SQL Server development.