Re: A general question about SQL statement
From: Bob Grommes (bob_at_bobgrommes.com)
Date: 08/13/04
- Next message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Running code as a transaction takes 3 times longer"
- Previous message: Julie: "Re: NUnit and C#"
- In reply to: Michael: "A general question about SQL statement"
- Next in thread: Tim Holgerson: "Re: A general question about SQL statement"
- Messages sorted by: [ date ] [ thread ]
Date: Fri, 13 Aug 2004 09:04:37 -0700
SQL Server caches commands and precompiles them. If the command string does
not change from one call to the next, as is the case with a parameterized
query, performance is significantly increased. But if you build the values
into the command string, it will change virtually every time, defeating this
optimization.
I haven't seen any benchmarks, and one's mileage probably varies, but
parameterized SQL statements probably approach the performance level of
stored procedures in some cases, particularly batch processes. The main
performance advantage of stored procedures would be that in most cases there
would be no server-side compiles at all, not even on the first call.
--Bob
"Michael" <m@m.com> wrote in message
news:O6sZpnMgEHA.1652@TK2MSFTNGP09.phx.gbl...
> Hi all,
>
> I would like to get people's opinion about executing SQL statements in C#
> (or any other .NET language really). I used to create my SQL statement by
> building a string and replacing single quote with two single quotes.
> Sometimes, I used SqlParameter. Maybe, I'm a bit lazy when I build the SQL
> string. Should I always use SqlParameters? What are the
> advantages/disadvantages between building SQL string and using
SqlParameter?
> Does one perform better than the other?
>
> Thanks.
> Michael
>
>
- Next message: Cowboy \(Gregory A. Beamer\) [MVP]: "Re: Running code as a transaction takes 3 times longer"
- Previous message: Julie: "Re: NUnit and C#"
- In reply to: Michael: "A general question about SQL statement"
- Next in thread: Tim Holgerson: "Re: A general question about SQL statement"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|