T-SQL Programming in SQL Server – SQL Server Tutorial

T-SQL Programming in SQL Server:-

TSQL program is called “TSQL BLOCK”.

TSQL Blocks are two types:-

(I) Anonymous blocks

(II) Named blocks:                                        

  1. Procedures
  2. Functions
  3. DB triggers

(I) Anonymous Blocks in SQL Server :-

Declare statement :

  • It is used to declare a variable.

Syntax : declare @ varname data type.

Example  :-  

Declare @ X int

Declare @ s varchar(2) ,@ d date time.

Set statement  :-

  • It is used to assign value to a variable.

       Set @ varname = value

       Set @ x=100

Print statement :-

  • It is used to print messages (or) variables.

Print ‘hello’

declare @x int, @y int, @z int

Set @ x=10

Set @ y =20

Set @z=@x+@y

Print ’sum of two nos =’+cast(@z as varchar)

Leave a Reply

Your email address will not be published. Required fields are marked *