What is "@@" in SQL Server

What is the use of @@ in SQL Server?

+6
source share
3 answers

According to MSDN , the correct name for them is system functions .

The naming confusion (global variable, system function, global function) stems from the various terms used in the history of SQL Server. From the MSDN Transact-SQL Variables article :

The names of some Transact-SQL system functions begin with two characters (@@). Although in earlier versions of Microsoft SQL Server, @@ Functions are called global variables, they are not variables and do not have the same behavior as variables. The @@ functions are system functions, and their use of syntax follows the rules for functions.

Thus, the two characters "at" (@@) are used to denote some system functions. The use of the phrase “global variable” was deprecated (although you will still see some use it ), most likely because in the programming world a global variable is one value that is visible everywhere, and, as already mentioned, it’s not that happening here (e.g. @@IDENTITY ).

Further confusion is most likely caused by the name of the temporary tables. One hash character, a table name prefix, indicates a temporary table of a locally localized area (e.g., #MyLocalTable ), very similar to a single in a symbol representing a local range variable (e.g., @MyLocalVariable ). Adding a second hash character to a temporary table makes it global (for example, ##MyGlobalTable ), but trying to add two characters to a variable does not have the same effect .

+4
source

@ for local variable

@@ is for a global variable or function.

There are several standard global variables or functions, for example: @@IDENTITY , @@ROWCOUNT , @@TRANCOUNT

+3
source

@@ used to prefix internal statistics and metadata that return information about how SQL Server is configured, and not for a specific database.

For example, they include the number of connections to the database ( @@CONNECTIONS ) and the first day of the week ( @@DATEFIRST )

https://msdn.microsoft.com/en-us/library/ms173823.aspx

https://msdn.microsoft.com/en-us/library/ms177520.aspx

0
source

Source: https://habr.com/ru/post/985252/


All Articles