Microsoft SQL Server 2008 brings in a new feature of 'Declaring and Assigning' a variable all in a single line. Earlier, while using SQL 2005 and earlier versions, we had to declare a variable before assigning it. This feature is explained in detail below.
In SQL 2005 and earlier versions we had to write:
Declare @age int
Declare @name nvarchar(25)
Declare @date date
Set @age = 25
Set @name = "Garry"
Set @date = GETDATE()
With SQL 2008 we can combine both these statements to write
Declare @age int = 25
Declare @name nvarchar(25)
Declare @date @date = GETDATE()
Advantage : This helps us to write less code, yet get the same functionality.
Do share with us : Would you like to use this new method? If not, why?
Set @name = "Garry"
Set @date = GETDATE()
With SQL 2008 we can combine both these statements to write
Declare @age int = 25
Declare @name nvarchar(25)
Declare @date @date = GETDATE()
Advantage : This helps us to write less code, yet get the same functionality.
Even though this feature has been available it is not being used in many projects because of backward compatibility issue. If the same code is being used on both 2005 and 2008 server we would prefer writing in a format compatible to both.
Do share with us : Would you like to use this new method? If not, why?
Comments
Post a Comment