What is the usage of @@
in SQL Server?
%s is a placeholder used in functions like sprintf. Check the manual for other possible placeholders. $sql = sprintf($sql, "Test"); This would replace %s with the string "Test".
The @@OPTIONS function returns a bitmap of the options, converted to a base 10 (decimal) integer. The bit settings are stored in the locations described in a table in the topic Configure the user options Server Configuration Option.
The Microsoft SQL Server IN operator is used to replace a group of arguments using the = operator that are combined with an OR in for SELECT, UPDATE or DELETE statement. It can make code easier to read and understand.
There is no difference. The rules for variables state that they start with an '@' character and follow the rules for identifiers. Since '@' is a valid identifier character, you can have as many as you like at the start of your variable name.
@@
is used to prefix internal statistical and metadata functions that return information about how the SQL Server is configured, not specific to any particular database.
For example, these include the number of connections made 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
According to MSDN, the correct name for these is system functions
.
The naming confusion (global variable, system function, global function) stems from different terminology used throughout SQL Server's history. From the MSDN Transact-SQL Variables article:
The names of some Transact-SQL system functions begin with two at signs (@@). Although in earlier versions of Microsoft SQL Server, the @@functions are referred to as global variables, they are not variables and do not have the same behaviors as variables. The @@functions are system functions, and their syntax usage follows the rules for functions.
Thus, two 'at' symbols (@@) are used to denote some system functions. The use of the phrase "global variable" was deprecated (though you will still see some people use it), most likely because in the programming world a global variable is a single value that is visible everywhere, and as already pointed out that isn't what is happening here (e.g., @@IDENTITY
).
Further confusion is likely caused by the way temporary tables are named. A single hash sign prefixing a table name indicates a locally-scoped temporary table (e.g., #MyLocalTable
), much like a single at symbol indicates a locally-scoped variable (e.g., @MyLocalVariable
). Adding a second hash sign to a temporary table makes it globally-scoped (e.g., ##MyGlobalTable
), but trying to add two at symbols to a variable does not produce the same effect.
@
is for a local variable
@@
is for a global variable or function.
There are several standard global variables or functions, e.g.: @@IDENTITY
, @@ROWCOUNT
, @@TRANCOUNT
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With