SQL Server: Named Batches
In this article i will explain about Named Batches in SQL Server.
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.
2. Named Batches:
A group of statements which can be reffered by a name. Then that group/batch is called Named Batches. Three types of Named Batches are there.
It is a set of pre compiled statements which help in reusability.
Create procedure <procedure-name> ( <Argument1, Arguments2,... ) As Begin -- Multiple statements here. End
We can alter the existing procedure.
Alter procedure <procedure-name> ( <Argument1, Arguments2,... ) As Begin -- Multiple statements here. End
Add Two numbers using procedure:
Create procedure spAdd ( @a int, @b int ) As Begin -- Declare local variables. Declare @c int Set @c = @a+@b print 'Sum is: '+cast(@c as varchar) End
How to execute procedure:
There are several ways to execute a procedure.
Execute spAdd 10, 20 (or) Exec spAdd 10, 20
Sum is: 30
CreatedDec 21, 2013
UpdatedDec 21, 2013