Home > Query, SQL > BISQL # 79 – SQL Server Global Variable #1–Introduction, Why, What, How and Which are Global Variable with detailed explanation and Example

BISQL # 79 – SQL Server Global Variable #1–Introduction, Why, What, How and Which are Global Variable with detailed explanation and Example

Hi friends ,

Today I just thought of explain and doing some research on  global variable ,and my post is also on same topic.

In SQL Server Global Variable series we are going to looked in following as future post .

  1. SQL Server Global Variable #1 – Introduction of Global Variable
  2. SQL Server Global Variable #2 – Global Variable 12 of 36
  3. SQL Server Global Variable #3 – Global Variable 24 of 36
  4. SQL Server Global Variable #4 – Global Variable 36 of 36
  5. SQL Server Global Variable #5 – Summery of SQL Server Global Variable

In this Article we are going to cover

  • What is Global Variable
  • Why Global variable is needed
  • Where Global variable are stored
  • How to use Global variable
  • Which are list of Global variable

Global variable are most used variable in SQL Server as these are One of the important aspect and needed at various stages of development.

Now lets dig into various aspect of Global variable : 

What is Global Variable ?

  • Global variable are simple variables which are already present in SQL Server .
  • We never define SQL Server Global Variable.
  • Global variable names begin with an @@ prefix.
  • Server constantly Global Variable.
  • Global Variable are automatically updated and interact with system silently.
  • We cannot directly change them with a SET statement or a SELECT statement

Why Global variable is needed  ?

  • Global variables constitute a special type of variable.
  • The server maintains the values in these variables.
  • They carry information specific to the server or a current user session.
  • They can be examined from anywhere, whether from a stored procedure or a batch.
  • Sometime we required to interact with Different Database with singled value

Where Global variable are stored ?

  • Global variables are actually system functions .
  • This Function return various pieces of information about the current user environment for SQL Server.

How to use Global variable ?

We can directly use SELECT Statement for using Global variable

For example

@@Version is Global variables which returns information regarding SQL Server version 

SELECT @@VERSION

Output

image

Which are list of Global variable ?

Following is list of Global Variable in SQL Server .

@@CONNECTIONS    
@@MAX_CONNECTIONS     
@@CPU_BUSY             
@@ERROR              
@@IDENTITY             
@@IDLE                 
@@IO_BUSY             
@@LANGID              
@@LANGUAGE            
@@MICROSOFTVERSION     
@@PACK_RECEIVED      
@@PACK_SENT             
@@PACKET_ERRORS         
@@ROWCOUNT              
@@SERVERNAME         
@@SPID                 
@@TEXTSIZE             
@@TIMETICKS             
@@TOTAL_ERRORS         
@@TOTAL_READ            
@@TOTAL_WRITE        
@@TRANCOUNT             
@@VERSION              
@@CURSOR_ROWS        
@@DATEFIRST            
@@DEF_SORTORDER_ID    
@@DEFAULT_LANGID        
@@ERROR                
@@FETCH_STATUS        
@@LOCK_TIMEOUT        
@@MAX_PRECISION        
@@NESTLEVEL            
@@OPTIONS            
@@PROCID                
@@REMSERVER            
@@SERVICENAME        

We will have detailed explanation on each of this variable in my next post

Hope this Helps !!!!

Thanks for visiting my blog !!

Hope you will like this post on Introduction,Why,What,How and Which are Global Variable with detailed explanation and Example.

If you really like reading my blog and understood at lest few thing then please don’t forget to subscribe my blog .

If you wan daily link and analysis or interesting link go to following website which will give @ your inbox please subscribe our following link resource blog

Where todays links are

Link Resource Website

Advertisements
Categories: Query, SQL
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: