Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

9
  • I have tried the formatting and performance arguments, but they still aren't convinced. Commented May 26, 2009 at 12:53
  • 5
    Actually, sql server can re-use the query plan whether you use parameters or not. I agree with the other arguments, but for most cases the performance argument for parameterized sql doesn't fly anymore. Commented May 26, 2009 at 15:07
  • 1
    @tnyfst: it can reuse the execution plan when the query string changes for every combination of parameter values? I did not think that possible. Commented May 26, 2009 at 16:29
  • 4
    The query plan will be reused if the query text is IDENTICAL to an earlier query text. So if you send the EXACT SAME query twice, it will be reused. However, if you change even just a space or a comma or something, a new query plan will have to be determined. Commented May 26, 2009 at 18:44
  • 1
    @Marc: I'm not sure you are entirely correct. SQL Servers caching hueristics are a little weird. The parser is capable of identifying constants in the text and can convert the SQL string to one the uses parameters artificially. It can then insert into the cache the text of this new parameterised query. Subsequent similar SQL may find its parameterised version matched in the cache. However, parameterised versions aren't always used with the originaly SQL versions being cached instead, I suspect SQL has a zillion performance related reasons to choose between the two approaches. Commented May 28, 2009 at 12:35