Connecting Tech Pros Worldwide Help | Site Map

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

rooster575
Guest
 
Posts: n/a
#1: Nov 18 '05
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.


Aaron [SQL Server MVP]
Guest
 
Posts: n/a
#2: Nov 18 '05

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


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

--
http://www.aspfaq.com/
(Reverse address to reply.)




"rooster575" <rooster575@hotmail.com> wrote in message
news:%23p06xSgaEHA.3716@TK2MSFTNGP11.phx.gbl...[color=blue]
> 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.[/color]


rooster575
Guest
 
Posts: n/a
#3: Nov 18 '05

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


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



"Aaron [SQL Server MVP]" <ten.xoc@dnartreb.noraa> wrote in message
news:uRLumagaEHA.2516@TK2MSFTNGP10.phx.gbl...[color=blue]
> They will execute in order. However, why aren't you using a stored
> procedure for this???
>
> --
> http://www.aspfaq.com/
> (Reverse address to reply.)
>
>
>
>
> "rooster575" <rooster575@hotmail.com> wrote in message
> news:%23p06xSgaEHA.3716@TK2MSFTNGP11.phx.gbl...[color=green]
> > 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,[/color][/color]
then[color=blue][color=green]
> > 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.[/color]
>
>[/color]


Closed Thread