Difference between a command and a statement

    1. What is the difference between a command and a statement?
    2. Also, what is the difference between a batch and a transaction?  I believe that both executes multiple statements at once.

     

    Any links and/or videos would be helpful.

    1. Interesting question because it's really easy to get sloppy about these. I'm sure I do all the time. Here's Microsoft's tutorial on writing T-SQL Statements. Pretty sure there isn't anything more authoritative than that. Sadly, another Microsoft reference calls them T-SQL commands. I would say, there isn't a fundamental difference between a statement and a command. It's just two words that mean the same and are used interchangeably. Interestingly enough, the second link, which refers to commands, has a sub-section entitled, statements. That's separated from queries, which I always considered either a T-SQL command or statement.

      Whew!

      Don't sweat #1. Instead, focus on the two types of queries, DDL or DML, Data Definition Language or Data Manipulation Language. Then, focus on the details of all the different functions and, gods forgive me, commands, within those languages.

    2. Now here, there are clear definitions. A transaction is a unit of work that is commited or rolled back as that unit. A transaction is either implicit or explicit. By default, everything gets an implicit transaction, whether you declare it or not. However, read through the link, there's a ton around this concept.

      A batch is different. It's a collection of t-sql statements. The GO command, not a T-SQL statement, does a good job of outlining what a batch is and some of the rules around them.

    Oh, and while we're here, how fun is the opening line of the GO documentation based on your first question: "SQL Server provides commands that are not Transact-SQL statements..."

    I hope this adds a little clarity.

    "The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
    - Theodore Roosevelt

    Author of:
    SQL Server Execution Plans
    SQL Server Query Performance Tuning

Viewing 2 posts - 1 through 1 (of 1 total)

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