SQL Server: Anonymous Batches

 SQL Server     sbo     Updated on Dec 21, 2013     VIKRAM     563   

Introduction:

In this article i will explain about Anonymous Batches in SQL Server.

Description:

In previous articles i explained about joins, and Batches. Now i will explain about Anonymous Batches in SQL Server.

Batches:

A batch is a group of sql statements. Which are executed as unit. Two types of batches are there. 1). Anonymous Batches and 2). Named Batches

1. Anonymous Batches:

A group of statements which can't be reffered by a name. Then that group/batch is called Anonymous Batches.

Example:

Begin

    Declare @a int
    Declare @b int
    Set @a = 10
    Set @b = 20
    Declare @c int
    Set @c = @a + @b;
    print 'Sum is: '+cast(@c as varchar)
    
End

Output:

Sum is: 30

Note:

Here @a, @b, and @c are Local variables.

  Related Articles
SQL Server: Triggers
SQL Server: Difference between Stored Procedure and Function
SQL Server: Functions
SQL Server: Named Batches
SQL Server: Batches
  Recent Articles
SQL Server: Triggers
SQL Server: Difference between Stored Procedure and Function
SQL Server: Functions
SQL Server: Named Batches
SQL Server: Batches