Local variable and global variables in SQL. [Resolved]

Posted by Allemahesh under Sql Server on 7/22/2013 | Points: 10 | Views : 4303 | Status : [Member] [MVP] | Replies : 1
What is the main different between local variable and global variables in SQL?


Posted by: Kmandapalli on: 7/23/2013 [Member] Silver | Points: 50



SQL Server local variables are declared using the DECLARE statement, and exist for the duration of the batch in which they are declared.
They are declared with @ prefix.

SQL Server provides a massive number of global variables, which are very effective to use in our regular Transact-SQL. 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.

Mark as answer if satisfied.......

Thank You,
Kavya Shree M.

Kavya Shree Mandapalli

Allemahesh, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response