Results 1 to 2 of 2

Thread: Stored procedure Vs SQL Statement

  1. #1
    Join Date
    Jan 2008
    Posts
    1

    Stored procedure Vs SQL Statement

    Hi Friends - I would like to know which is more efficient and faster between Stored Proceure and writting SQL Statement in your code.

    What I am trying to find out is, will it be better to use a stored procedire to get your records or get your records by writting SQL statement in your code.

    Which one of the 2 should be used?

    Plese help....

    Thanks

  2. #2
    Join Date
    Dec 2004
    Posts
    502
    You should try to put as many SQL statements into stored procedures as possible. With MS SQL Server, the stored procedure's execution plan will be compiled and saved with the stored procedure so it won't have to be re-created every time it's run (which is what will happen with a SQL statement in code). Creating the execution plan can consume a lot of time with a complex statement. However, one potential downside is if the stored procedure accepts parameters. It's possible (thought not common) for a particular parameter to need an execution plan that's different and better than the one saved for that particular stored procedure. In these cases, you might have to force a stored procedure recompile to get the most efficient plan. There are other good reasons to use stored procedures, but that to me is the most important one in relation to efficiency.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •