Re: Confused about proc vs. dynamic SQL vs LINQ



On Apr 30, 4:55 pm, "Nicholas Paldino [.NET/C# MVP]"
<m...@xxxxxxxxxxxxxxxxxxxxxxxxxxx> wrote:
Generally speaking, stored procedures are going to be faster than
dynamic sql. In the case of SQL Server, you might get just as fast
performance from dynamic sql (sql that you generate on the client and issue
to the server, as opposed to executing the stored procedure with parameters)
depending on the cache (dynamic queries are cached to a degree, and whether
or not they are reused depends on how often the cache is hit, as well as if
the queries are the same and a number of other factors). With stored
procedures, the execution plan is already compiled, and the server won't
have to recompile it. Depending on the statistics that were in place when
the stored procedure was compiled, and the statistics that are in place when
you execute your dynamic sql, you might get a different execution plan
(assuming you are executing the same sql dynamically that you are executing
in the stored procedure.

As of Sql Server 7, that's not true. Sql Server doesn't 'compile'
stored procedures at all. It just checks syntax. Either method you
use will cause sql to create an execution plan and cache it. After
that, it will used the cached plan either way. Check the BOL.

.



Relevant Pages

  • Re: Sending NULL value to parameter of Stored Procedure
    ... With that number of options dynamic SQL is the best option, you need to understand the implications, SQL injection, multiple plans. ... Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.fulltext)
  • Re: Sending NULL value to parameter of Stored Procedure
    ... With that number of options dynamic SQL is the best option, ... Have a read of Erlands Dynamic sql article http://www.sommarskog.se/dynamic_sql.html ... Looking for a SQL Server replication book? ...
    (microsoft.public.sqlserver.fulltext)
  • Re: DENY table SELECT, GRANT stored proc EXEC, but EXECUTE a string
    ... To be able to use dynamic SQL, the user must have direct SELECT permissions ... Vyas, MVP (SQL Server) ... > were using static statements in our stored procs instead of EXECUTE, ...
    (microsoft.public.sqlserver.security)
  • Re: Flattening Parent Child, an issue, please help
    ... Execute the SQL string. ... It's a plain applicaiton of dynamic SQL, and the newsgroups for SQL Server ...
    (comp.databases.ms-sqlserver)
  • Re: Why cant I execute this script in ADO?
    ... > I checked your great tool, though I saw that you have two ways of SQL ... > statements executing... ... while the "Script" tab accepts a script ... Database Workbench - developer tool for InterBase, Firebird, MySQL & MS SQL Server. ...
    (borland.public.delphi.database.ado)