background preloader

T-SQL

Facebook Twitter

IF...ELSE (Transact-SQL) WHERE (Transact-SQL) Predicates (Transact-SQL) IS [NOT] NULL (Transact-SQL) Expression IS [ NOT ] NULL expression Is any valid expression.

IS [NOT] NULL (Transact-SQL)

Specifies that the Boolean result be negated. The predicate reverses its return values, returning TRUE if the value is not NULL, and FALSE if the value is NULL. If the value of expression is NULL, IS NULL returns TRUE; otherwise, it returns FALSE. Logical Operators (Transact-SQL) Operators (Transact-SQL) Expressions (Transact-SQL) Is a combination of symbols and operators that the SQL Server Database Engine evaluates to obtain a single data value.

Expressions (Transact-SQL)

Simple expressions can be a single constant, variable, column, or scalar function. Operators can be used to join two or more simple expressions into a complex expression. Data Types (Transact-SQL) In SQL Server, each column, local variable, expression, and parameter has a related data type.

Data Types (Transact-SQL)

A data type is an attribute that specifies the type of data that the object can hold: integer data, character data, monetary data, date and time data, binary strings, and so on. SQL Server supplies a set of system data types that define all the types of data that can be used with SQL Server. CREATE PROCEDURE (Transact-SQL) Schema_name The name of the schema to which the procedure belongs.

CREATE PROCEDURE (Transact-SQL)

Procedures are schema-bound. CASE (Transact-SQL) Evaluates a list of conditions and returns one of multiple possible result expressions.

CASE (Transact-SQL)

The CASE expression has two formats: The simple CASE expression compares an expression to a set of simple expressions to determine the result. The searched CASE expression evaluates a set of Boolean expressions to determine the result. Both formats support an optional ELSE argument. CASE can be used in any statement or clause that allows a valid expression. Search Condition (Transact-SQL) Specifies the conditions for the rows returned in the result set for a SELECT statement, query expression, or subquery.

Search Condition (Transact-SQL)

For an UPDATE statement, specifies the rows to be updated. For a DELETE statement, specifies the rows to be deleted. There is no limit to the number of predicates that can be included in a Transact-SQL statement search condition. Negates the Boolean expression specified by the predicate. For more information, see NOT (Transact-SQL). Combines two conditions and evaluates to TRUE when both of the conditions are TRUE. Combines two conditions and evaluates to TRUE when either condition is TRUE. Is an expression that returns TRUE, FALSE, or UNKNOWN. expression Is a column name, a constant, a function, a variable, a scalar subquery, or any combination of column names, constants, and functions connected by an operator or operators, or a subquery. Is the operator used to test the equality between two expressions. string_expression Is a string of characters and wildcard characters. MERGE (Transact-SQL) WITH <common_table_expression> Specifies the temporary named result set or view, also known as common table expression, defined within the scope of the MERGE statement.

MERGE (Transact-SQL)

The result set is derived from a simple query and is referenced by the MERGE statement. For more information, see WITH common_table_expression (Transact-SQL). TOP ( expression ) [ PERCENT ] Specifies the number or percentage of rows that are affected. expression can be either a number or a percentage of the rows. The TOP clause is applied after the entire source table and the entire target table are joined and the joined rows that do not qualify for an insert, update, or delete action are removed. Because the MERGE statement performs a full table scan of both the source and target tables, I/O performance can be affected when using the TOP clause to modify a large table by creating multiple batches. SELECT (Transact-SQL) Retrieves rows from the database and enables the selection of one or many rows or columns from one or many tables in SQL Server 2012.

SELECT (Transact-SQL)

The full syntax of the SELECT statement is complex, but the main clauses can be summarized as: [ WITH <common_table_expression>] SELECT select_list [ INTO new_table ] [ FROM table_source ] [ WHERE search_condition ] [ GROUP BY group_by_expression ] [ HAVING search_condition ] [ ORDER BY order_expression [ ASC | DESC ] ] The UNION, EXCEPT and INTERSECT operators can be used between queries to combine or compare their results into one result set. SELECT Examples (Transact-SQL) This topic provides examples of using the SELECT statement.

SELECT Examples (Transact-SQL)

The following example shows three code examples. This first code example returns all rows (no WHERE clause is specified) and all columns (using the *) from the Product table in the AdventureWorks2012 database. USE AdventureWorks2012; GO SELECT * FROM Production.Product ORDER BY Name ASC; -- Alternate way. USE AdventureWorks2012; GO SELECT p.* FROM Production.Product AS p ORDER BY Name ASC; GO This example returns all rows (no WHERE clause is specified), and only a subset of the columns (Name, ProductNumber, ListPrice) from the Product table in the AdventureWorks2012 database.

USE AdventureWorks2012; GO SELECT Name, ProductNumber, ListPrice AS Price FROM Production.Product ORDER BY Name ASC; GO This example returns only the rows for Product that have a product line of R and that have days to manufacture that is less than 4.