Transact-SQL Syntax Elements

Accessing and Changing Relational Data

Accessing and Changing Relational Data

Transact-SQL Syntax Elements

Transact-SQL has several syntax elements that are used by, or influence, most statements:

Identifiers

Are the names of objects such as tables, views, columns, databases, and servers.

Data types

Define the types of data contained by data objects, such as columns, variables, and parameters. Most Transact-SQL statements do not reference data types explicitly, but the results of most statements are influenced by the interactions between the data types of the objects referenced in the statement.

Functions

Are syntax elements that take zero, one, or more input values and return a scalar value or a tabular set of values. Examples include the SUM function for adding several values, the DATEDIFF function for determining how many units of time separate two dates, the @@SERVERNAME function for getting the name of an instance of Microsoft® SQL Server™, or the OPENQUERY function for executing a Transact-SQL statement against a remote server and retrieving the result set.

Expressions

Are units of syntax that Microsoft SQL Server can resolve to single values. Examples of expressions include constants, functions that return a single value, a reference to a column, or a variable.

Operators

Work with one or more simple expressions to form a more complex expression. For example, combining the minus sign (-) with the constant 12 results in the constant -12. The multiplication sign (*) in the expression PriceColumn *1.1 increases the price by 10 percent.

Comments

Are pieces of text inserted into Transact-SQL statements or scripts to explain the purpose of the statement. The comments are not executed by SQL Server.

Reserved Keywords

Are words reserved for the use of SQL Server and should not be used for the names of objects in a database.