Difference between SQL queries and batches?

  • Hi ,

    I am newbie. I would like to what is the difference between SQL queries and Batches. According to MSDN Batches means "A batch is a group of one or more Transact-SQL statements" and to me the same means SQL Queries. In SQL queries we can have more then one T-SQL statement. So what is the difference between the two?

  • A query is a single select, insert, update or delete (or related) statements. A batch is a set of one or more statements that are submitted to the server as a single unit.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass
  • Batches are terminated by the GO command.

    See: http://msdn.microsoft.com/en-us/library/ms188037.aspx

  • laurie-789651 (10/3/2012)


    Batches are terminated by the GO command.

    See: http://msdn.microsoft.com/en-us/library/ms188037.aspx

    Only in a script. The execution of a stored procedure (for example) can be considered to be a "batch" depending on how it's called.

    --Jeff Moden


    RBAR is pronounced "ree-bar" and is a "Modenism" for Row-By-Agonizing-Row.
    First step towards the paradigm shift of writing Set Based code:
    ________Stop thinking about what you want to do to a ROW... think, instead, of what you want to do to a COLUMN.

    Change is inevitable... Change for the better is not.


    Helpful Links:
    How to post code problems
    How to Post Performance Problems
    Create a Tally Function (fnTally)

  • And a script without any GO is a single batch, no matter how long it is.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 5 posts - 1 through 4 (of 4 total)

You must be logged in to reply to this topic. Login to reply