Wednesday, 18 December 2013

T-SQL - Local Variables

Local Variables 

Variables are used to store the values so that these values can be used later.

Syntax

Declaration:   DECLARE @Variable_name Data_type;
Initilization:  SET @Variable_name = value;

For later versions of SQL Server  2005, we can declare and set the value of variables in single line.
 e.g. DECLARE My_Variable int =10;
Scope

Scope of the local variables is between the declaration of the variable and the end of the current batch.

Example 1


Example 2

 
Example 3


 

Example 4
Declare a variable in a query window and try to select it in another query window you will get an error. This is because of scope of local variable.





Thursday, 22 August 2013

Save Changes in a Table through Design View in SQL Server 2008

Hello Friends, hope you all are doing great. Yesterday I encountered a problem while working in Microsoft SQL Server 2008. I want to make changes in existing table through design view but when I press Ctrl+S, instead of saving the changes a window appeared showing the options to save the script. 

No need to worry, by following simple steps you can save changes through design view. 
Go to  
  • Tools
  • select Options 
  • select Designers 
  • select Table and Database Designers 
 Here you will find an option prevent saving changes that require table re-creation, Uncheck this option. 
And now you can save changes in your table through design view by pressing ctrl+s. Cheers

 



Sunday, 18 August 2013

First Blog Post

Finally I am posting my first blog. It was not an easy task for me to choose the blog name. It seems very true that choosing a name for your blog is just like choosing a name for a new born baby LOL .
I had a plan to start blogging since long but couldn't do that. I will be sharing my everyday learning and experiences in this blog on daily basis.