Click here to Skip to main content
15,888,984 members
Home / Discussions / Database
   

Database

 
GeneralRe: Multiple Instances - SQLSERVER Pin
clint198216-Mar-07 8:26
clint198216-Mar-07 8:26 
Questionstored procedures Vs dynamic SQL Pin
digsy_16-Mar-07 3:40
digsy_16-Mar-07 3:40 
AnswerRe: stored procedures Vs dynamic SQL Pin
Pete O'Hanlon16-Mar-07 3:44
mvePete O'Hanlon16-Mar-07 3:44 
GeneralRe: stored procedures Vs dynamic SQL Pin
digsy_16-Mar-07 3:56
digsy_16-Mar-07 3:56 
GeneralRe: stored procedures Vs dynamic SQL Pin
Pete O'Hanlon16-Mar-07 4:09
mvePete O'Hanlon16-Mar-07 4:09 
GeneralRe: stored procedures Vs dynamic SQL Pin
digsy_16-Mar-07 4:51
digsy_16-Mar-07 4:51 
GeneralRe: stored procedures Vs dynamic SQL Pin
Pete O'Hanlon16-Mar-07 13:02
mvePete O'Hanlon16-Mar-07 13:02 
AnswerRe: stored procedures Vs dynamic SQL Pin
Mike Dimmick16-Mar-07 6:44
Mike Dimmick16-Mar-07 6:44 
SQL Server compiles an execution plan for a query the first time it's run. That plan is then cached and reused. It will be discarded either when it's aged out of memory (i.e. there was enough memory pressure for query plans to be removed from memory, and this was less recently used/important than other cached plans) or when the statistics on the index columns have changed enough to force a recompile, or you add or remove some indexes on tables used in the query.

The same is true for stored procedures - their query plans are just weighted higher than dynamic SQL. It's got nothing to do with the .NET environment, it applies to all interfaces.

I'm concerned that queries using LIKE '%%' or OR @param='' etc will have a query plan constructed based on the first set of arguments supplied, but which will then be a poor plan for a different set of arguments, and SQL Server will reuse that initial plan rather than construct a better one. This is something I don't have data on, however - you should profile this. In this case I think dynamic SQL could be better.

You can mark a stored procedure to be recompiled every time by specifying WITH RECOMPILE. However, you incur the overhead of computing the plan every time; caching the dynamic SQL's plan might work better.

If your query does not use parameters, SQL Server will attempt to auto-parameterise the query so that it can reuse the plan for more queries. That is, it will replace explicit literal values with parameters. However, it may be better to mark the parameters yourself if there are literals in the query which don't change.

Stored procedures are useful as a security boundary - you can GRANT a user permission to EXECUTE a stored procedure even if they're denied permission to perform the operations of the SP directly.

Stability. What an interesting concept. -- Chris Maunder

QuestionMultiple Instances - SQLSERVER Pin
clint198216-Mar-07 3:39
clint198216-Mar-07 3:39 
AnswerRe: Multiple Instances - SQLSERVER Pin
Hesham Amin16-Mar-07 9:01
Hesham Amin16-Mar-07 9:01 
Questionhow we can use stored proceder with asp.net Pin
jayvaishnav8216-Mar-07 2:42
jayvaishnav8216-Mar-07 2:42 
AnswerRe: how we can use stored proceder with asp.net Pin
kubben16-Mar-07 2:47
kubben16-Mar-07 2:47 
AnswerRe: how we can use stored proceder with asp.net Pin
Marcus J. Smith16-Mar-07 2:47
professionalMarcus J. Smith16-Mar-07 2:47 
AnswerRe: how we can use stored proceder with asp.net Pin
Colin Angus Mackay16-Mar-07 3:37
Colin Angus Mackay16-Mar-07 3:37 
JokeRe: how we can use stored proceder with asp.net Pin
LongRange.Shooter16-Mar-07 7:48
LongRange.Shooter16-Mar-07 7:48 
GeneralRe: how we can use stored proceder with asp.net Pin
jayvaishnav8216-Mar-07 20:01
jayvaishnav8216-Mar-07 20:01 
GeneralRe: how we can use stored proceder with asp.net Pin
Colin Angus Mackay16-Mar-07 23:50
Colin Angus Mackay16-Mar-07 23:50 
Questioncopy data between 2 instances Pin
Ista16-Mar-07 2:35
Ista16-Mar-07 2:35 
AnswerRe: copy data between 2 instances Pin
kubben16-Mar-07 2:43
kubben16-Mar-07 2:43 
GeneralRe: copy data between 2 instances Pin
Ista16-Mar-07 3:08
Ista16-Mar-07 3:08 
GeneralRe: copy data between 2 instances Pin
kubben16-Mar-07 3:21
kubben16-Mar-07 3:21 
GeneralRe: copy data between 2 instances Pin
Colin Angus Mackay16-Mar-07 3:38
Colin Angus Mackay16-Mar-07 3:38 
QuestionMultiple User tables? Pin
kbalias16-Mar-07 1:41
kbalias16-Mar-07 1:41 
AnswerRe: Multiple User tables? Pin
N a v a n e e t h16-Mar-07 1:50
N a v a n e e t h16-Mar-07 1:50 
GeneralRe: Multiple User tables? Pin
Pete O'Hanlon16-Mar-07 2:13
mvePete O'Hanlon16-Mar-07 2:13 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.