3 SQL queries in 1 string...in what order will they execute?

R

rooster575

Im running a querystring in vb.net and it seems as though SQL server decides
on the order in which to run the 3 queries in the string.. Is this possible?
I would think that SQL server starts with the 1st query, executes it, then
goes to the next.

For example:
************************************************************
Dim myQueryString as string = _
"INSERT INTO ArchivedClients(ClientNo,ClientName) " & _
"SELECT ClientNo,ClientName FROM Clients WHERE State='PA';" & _
"DELETE FROM Clients WHERE State='PA';" & _
"UPDATE someTable SET someField='thisstring';"

Dim SqlCommand As New SqlCommand(myQueryString, SqlConnection)
SqlCommand.ExecuteNonQuery()
************************************************************

Within the above there are 3 separate SQL queries.
Will SQL Server run them in 1-2-3 order, or is
it possible that it will switch the routine.

Thanks for any help.
 
A

Aaron [SQL Server MVP]

They will execute in order. However, why aren't you using a stored
procedure for this???
 
R

rooster575

Thanks very much, Aaron. I thought[hoped] that was the case.

I do use stored procedures when the particular query is highly used and of a
somewhat standard format. [2-3 dozen]
But, in my large web app of approx. 900-1200 asp.net pages ,with many unique
queries, I pick and choose which ones are best suited for a sproc. Many of
my queries are quite ad-hoc in nature, and I've found very little gain once
I work the magic necessary to run ad-hocs in sp's.
[Mostly though, its the sheer magnitude of different queries.]

Thanks again.
-R
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,048
Latest member
verona

Latest Threads

Top