Global variables
Global variables play a very important role in SQL server. Which are very effective to use in our regular Transact-SQL. In my article I am trying to describe it in a simple architecture.
Global variables represent a special type of variable. The server always maintain the values of these variables. All the global variables represent information specific to the server or a current user session.
Global variable names begin with a @@ prefix. You do not need to declare them, since the server constantly maintains them. They are system-defined functions and you cannot declare them.
Some example of commonly used global variable are mentioned bellow.
- @@CONNECTIONS
- @@MAX_CONNECTIONS
- @@CPU_BUSY
- @@ERROR
- @@IDENTITY
- @@IDLE
- @@IO_BUSY
- @@LANGID
- @@LANGUAGE
- @@MAXCHARLEN
- @@PACK_RECEIVED
- @@PACK_SENT
- @@PACKET_ERRORS
- @@ROWCOUNT
- @@SERVERNAME
- @@SPID
- @@TEXTSIZE
- @@TIMETICKS
- @@TOTAL_ERRORS
- @@TOTAL_READ / @@TOTAL_WRITE
- @@TRANCOUNT
- @@VERSION
SELECT @@VERSION [SQL SERVER VERSION]
For better understanding of each global variable please refer to MSDN or MS Related document.
I think the information is quite informative and thanking you to provide your valuable time on it.