Today, almost every modern programmer knows what Transact-SQL is. This is the extension that is used in SQL Server. This development is tightly integrated into the Microsoft SQL language and adds programming constructors that are not initially provided in the databases. T-SQL supports variables, as in most other designs. However, this extension restricts the use of variables in ways that are not common in other environments.
Declaring Variables in DECLARE SQL
T-SQL uses the DECLARE statement (<var_name>) to declare a variable. For example, in the case of declaring the variable i as an integer using this operator, the command would look like this: DECLARE @i int.
Microsoft , T-SQL AS , : DECLARE @i AS int. AS DECLARE. , AS, - , SQL Server 2000. , .
DECLARE SQL:
T-SQL , , . - ( ), . , . , Query Analyzer GO, , . , , SQL Server . , , .
SQL Declare Table:
DECLARE @mytable table
col1 int NOT NULL
INSERT INTO @mytable VALUES (1)
GO
, :
DECLARE @mytable table
col1 int NOT NULL
INSERT INTO @mytable VALUES (1)GO
INSERT , , :
: Msg 137, 15, 2, 2.
( DECLARE, SET)
Support for local variables in SQL procedures allows you to assign and retrieve data values in support of procedure logic. Variables in procedures are defined using the DECLARE SQL statement. Values can be assigned to variables using the SET statement or as the default value when declaring a variable. Literals, expressions, query results, and special register values can be assigned variables.
Variable values can be assigned to procedure parameters, other variables, and can also be specified as parameters in SQL statements executed within the procedure.Algorithm
, DEFAULT. Boolean FALSE. SET . SELECT FETCH INTO. VALUES INTO .
GET DIAGNOSTICS . GET DIAGNOSTICS ( UPDATE, DELETE - DELETE) SQL-
DECLARE SQL , , . , DELETE, GET DIAGNOSTICS , v_rcount , , is_done TRUE.
DECLARE SQL - , SQL, . .
SQL-. , , , .
, . SQL, , , .
SQL- , . , , . SQL CREATE PROCEDURE. , . , SQL-
Transact-SQL - , . :
Transact-SQL (@@). Microsoft SQL Server @@ . @@ - , .
DECLARE Transact-SQL :
- , @ ;
- ;
- .
- XML .
- NULL. , DECLARE SQL- @mycounter int.
, , . , @LastName, @FirstName @StateProvince NULL. - Transact-SQL, . , , .