Global variables are pre-defined system variables. It starts with @@. It provides information about the present user environment for SQL Server. SQL Server provides multiple global variables, which are very effective to use in Transact-SQL. The following are some frequently used global variables –
These are explained as following below.
- @@SERVERNAME :
This is used to find the name of the machine/computer on which SQL Server is running.
- @@CONNECTIONS :
This is used to find number of logins or attempted logins since SQL Server was last started.
- @@MAX_CONNECTIONS :
This is used to find the maximum number of simultaneous connections that can be made with SQL Server or instance in this computer environment.
- @@CPU_BUSY :
This is used to find the amount of time, in microseconds, that the CPU has spent doing SQL Server work since the last time SQL Server was running.
- @@ERROR :
This is used to check the error status (succeeded or failed) of the most recently executed statement. It contains Zero (0) if the previous transaction succeeded, else, it contains the last error number generated by the system.
- @@IDLE :
The amount of time, in microseconds, that SQL Server has been idle since it was last started.
- @@LANGUAGE :
This is used to find the name of the language that is currently used by the SQL Server.
- @@TRANCOUNT :
This is used to count the number of open transactions in the current session.
- @@VERSION :
This is used to find the current version of the SQL Server Software.
Microsoft SQL Server 2014 (SP3-CU-GDR) (KB4535288) - 12.0.6372.1 (X64) Dec 12 2019 15:14:11 Copyright (c) Microsoft Corporation Standard Edition (64-bit) on Windows NT 6.3 <X64> (Build 9600: ) (Hypervisor)
- Difference between Structured Query Language (SQL) and Transact-SQL (T-SQL)
- Delete statement in MS SQL Server
- SQL Server Mathematical functions (SQRT, PI, SQUARE, ROUND, CEILING & FLOOR)
- SQL Server Identity
- SQL SERVER | Conditional Statements
- SQL Server | STUFF() Function
- SQL Server | SERVERPROPERTY()
- Mean and Mode in SQL Server
- Allow only alphabets in column in SQL Server
- SQL SERVER | IN Condition
- Reverse Statement Word by Word in SQL server
- Copy tables between databases in SQL Server using Import-and-Export Wizard
- Difference between MySQL and MS SQL Server
- Comparisons between Oracle vs SQL Server
- Introduction of MS SQL Server
- Select statement in MS SQL Server
- Order by in MS SQL Server
- Distinct clause in MS SQL Server
- Where clause in MS SQL Server
- Difference between Couchbase and MS SQL Server
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.