ARTICLE

Using Query Batch in T-SQL

Posted by Sapna Articles | Database & DBA April 04, 2011
Query Batch is a group of one or more Transact-SQL statements sent at the same time from an application to SQL Server for execution
 
Reader Level:

T-SQL (Transact SQL) is a proprietary SQL extension used by Microsoft SQL Server and Sybase SQL Server. T-SQL adds extensions for procedural programming. Transaction-SQL is an extended form of SQL that adds declared variables, transaction control, error and exception handling and row processing to SQL's existing functions. Microsoft SQL and Sybase both support T-SQL statements It is largely SQL-92 compliant, so if you're familiar with another vendor's flavor of SQL, you'll probably feel right at home with Transact-SQL.

Query Batch

A batch is a group of one or more Transact-SQL statements sent at the same time from an application to SQL Server for execution. The most important characteristic of a batch is that it is parsed and executed on the server as an undivided entity. In some cases, batches are created implicitly. SQL Server compiles the statements of a batch into a single executable unit, called an execution plan. The statements in the execution plan are then executed one at a time.

The given below example shows how to execute query batch:- 

Example:

1> create table workers(
2>     ID          int,
3>     name        nvarchar (20),
4>     salary      int,
5>     start_date  datetime,
6>     city        nvarchar (20),
7>     region      char (5))
8> GO

1>
2> --Inserting Records in a Query Batch
3>
4> SET QUOTED_IDENTIFIER OFF
5> GO
1> INSERT INTO workers (ID, Name) VALUES(01,"Ravi")
2> INSERT INTO workers (ID, Name) VALUES(02,"sapna")
3> INSERT INTO workers (ID, Name) VALUES(03,"Pankaj")
4> INSERT INTO workers (ID, Name) VALUES(04,"Udas")
5> GO

(1 rows affected)

(1 rows affected)

(1 rows affected)

(1 rows affected)

1>
2> select * from workers
3> GO

   ID          name      salary      start_date       city      region
  -----     ---------- ----------- -------------  ----------  -------
   01         Ravi         NULL          NULL         NULL      NULL
   02         sapna       NULL          NULL         NULL      NULL
   03         Pankaj      NULL          NULL         NULL      NULL
   04         Udas        NULL          NULL         NULL      NULL

(3 rows affected)

Happy Learning

Login to add your contents and source code to this article
share this article :
post comment
 
Team Foundation Server Hosting
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications.
    Get 2 Months Free of ASP.NET Hosting for Only $4.95/month! Receive FREE MS SQL and MySQL Databases Including ASP.NET 4/3.5, MVC 3.0, Silverlight 4, Windows 2008/IIS 7.0 Plus FREE IIS 7 Modules. Host UNLIMITED ASP.NET Web Sites - Click Here!
Nevron Diagram
Become a Sponsor