SQL服务器中'@@'的用法是什么
What is the usage of '@@' in SQL Server
@@
在SQL服务器中有什么用?
@@
用于为内部统计和元数据函数添加前缀,这些函数 return 有关如何配置 SQL 服务器的信息,不特定于任何特定数据库。
例如,这些包括与数据库建立的连接数 (@@CONNECTIONS
) 和一周的第一天 (@@DATEFIRST
)
@
用于局部变量
@@
用于全局变量或函数。
有几个标准的全局变量或函数,例如:@@IDENTITY
、@@ROWCOUNT
、@@TRANCOUNT
According to MSDN,它们的正确名称是 system functions
。
命名混乱(全局变量、系统函数、全局函数)源于 SQL 服务器历史中使用的不同术语。来自 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.
因此,两个'at'符号(@@)被用来表示一些系统功能。短语 "global variable" 的使用已被弃用(尽管您仍然会看到 some people use it),很可能是因为在编程世界中,全局变量是一个随处可见的单一值,正如已经指出的那样不是这里发生的事情(例如,@@IDENTITY
)。
进一步的混乱可能是由临时 table 的命名方式引起的。前缀为 table 名称的单个井号表示局部范围的临时 table(例如,#MyLocalTable
),就像单个 at 符号表示局部范围的变量(例如,@MyLocalVariable
).向临时 table 添加第二个井号使其具有全局范围(例如 ##MyGlobalTable
),但尝试向变量 does not produce the same effect 添加两个 at 符号。
@@
在SQL服务器中有什么用?
@@
用于为内部统计和元数据函数添加前缀,这些函数 return 有关如何配置 SQL 服务器的信息,不特定于任何特定数据库。
例如,这些包括与数据库建立的连接数 (@@CONNECTIONS
) 和一周的第一天 (@@DATEFIRST
)
@
用于局部变量
@@
用于全局变量或函数。
有几个标准的全局变量或函数,例如:@@IDENTITY
、@@ROWCOUNT
、@@TRANCOUNT
According to MSDN,它们的正确名称是 system functions
。
命名混乱(全局变量、系统函数、全局函数)源于 SQL 服务器历史中使用的不同术语。来自 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.
因此,两个'at'符号(@@)被用来表示一些系统功能。短语 "global variable" 的使用已被弃用(尽管您仍然会看到 some people use it),很可能是因为在编程世界中,全局变量是一个随处可见的单一值,正如已经指出的那样不是这里发生的事情(例如,@@IDENTITY
)。
进一步的混乱可能是由临时 table 的命名方式引起的。前缀为 table 名称的单个井号表示局部范围的临时 table(例如,#MyLocalTable
),就像单个 at 符号表示局部范围的变量(例如,@MyLocalVariable
).向临时 table 添加第二个井号使其具有全局范围(例如 ##MyGlobalTable
),但尝试向变量 does not produce the same effect 添加两个 at 符号。