405
Chapter 16: Programming with T-SQL
16
System functions can’t be created. There’s a fi xed set of system functions, all beginning
with two @ signs. (The more signifi cant ones are listed in Table 16-1.) The most commonly
used global variables are @@NestLevel, @@Rowcount, @@ServerName, and @@Version.
The system functions are being replaced by DMO information.
TABLE 16 -1 System Functions
System Function Returns Scope
@@DateFirst The day of the week currently set as the fi rst day of
the week; 1 represents Monday, 2 represents
Tuesday, and so on. For example, if Sunday is the
fi rst day of the week, @@DateFirst returns a 7.
Connection
@@Error The error value for the last T-SQL statement
executed.
Connection
@@Fetch_Status The row status from the last cursor fetch
command.
Connection
@@LangID The language ID used by the current connection. Connection
@@Language The language, by name, used by the current
connection.
Connection
@@Lock_TimeOut The lock timeout setting for the current
connection.
Connection
@@Nestlevel Current number of nested stored procedures. Connection
@@ProcID The stored procedure identifi er for the current
stored procedure. This can be used with sys
.objects to determine the name of the current
stored procedure, as follows:
SELECT name
FROM sys.objects
WHERE object_id =
@@ProcID;
Connection
@@RowCount Number of rows returned by the last T-SQL
statement.
Connection
@@ServerName Name of the current server. Server
@@ServiceName SQL Server’s Windows service name. Server
@@SPID The current connection’s server-process identi-
fi er — the ID for the connection.
Connection
@@TranCount Number of active transactions for the current
connection.
Connection
@@Version SQL Server edition, version, and service pack. Server
c16.indd 405c16.indd 405 7/30/2012 5:38:09 PM7/30/2012 5:38:09 PM
http://www.it-ebooks.info