tags:

views:

25

answers:

3

Hello,

In SQL server query analyzer, for executing stored procedure we use exec/execute command followed by name of the proc. In the same way what is the command line/execute statement for ‘select’ command. How this is handled internally by query analyzer.

Thanks in advance,

Pradeep

A: 

Just the select statement itself.

rursw1
+1  A: 

Just select the query you want to run and press F5 or Ctrl + E to execute a query. Nothing like execute (or any other keyword) is needed before the SQL queries.

Faisal Feroz
I know pressing F5 or Ctrl + E executes the query, I want to know how in handled internally.
Pradeep
Internally the query is parsed (lexically) and if it is found to be from one of the executable statements it is executed. In short you can say that it checked for the existance of keywords (tokens) like SELECT, INSERT, UPDATE, CREATE, DELETE as the very first token in the query.
Faisal Feroz
+1  A: 

RE:

How this is handled internally by query analyzer.

This is a highly abbreviated summary of a section from the book "Professional SQL Server 2008 Internals and Troubleshooting"

  1. The SQL Server Network Interface (SNI) on the client establishes a connection to a TDS endpoint and sends the SELECT statement as a TDS message.
  2. The SNI on the server unpacks the message and passes the SQL Command to the Command Parser
  3. The command parser checks if a suitable plan exists in the cache. If not it creates a query tree and passes it to the optimizer.
  4. The optimizer generates a query plan. (If required)
  5. The Query Executor processes the query.
  6. The results are sent back to the client using the TDS protocol.

It looks as though this page has considerably more details about some of these steps.

Martin Smith