Re: Stored procedure overhead - baffling - database gurus

Tech Tip: Click here to run a free scan for Windows Errors and optimize PC performance

From: Tom Moreau (tom_at_dont.spam.me.cips.ca)
Date: 03/11/04


Date: Thu, 11 Mar 2004 13:15:15 -0500

Some observations:

  a.. The return code should be int - not decimal.
  b.. What value should the @status_num variable have when there are > 0
rows in trade_transaction for the given @trade_id?
  c.. Is the datatype if trade_id in the trade_transaction table of type
int?
  d.. You can rewrite the IF as:

  if exists (select * from trade_transaction where trade_id = @TradeID)
      set @status_num = -1
  a.. You can also use the following if you want to set @status_num to zero
when there are > 0 rows in trade_transaction for the given @trade_id:
  select @status_num = case when exists (select * from trade_transaction
              where trade_id = @TradeID)then -1 else 0 end

--
Tom
---------------------------------------------------------------
Thomas A. Moreau, BSc, PhD, MCSE, MCDBA
SQL Server MVP
Columnist, SQL Server Professional
Toronto, ON Canada
www.pinnaclepublishing.com/sql
"Praty77" <praty77-google@yahoo.com> wrote in message
news:6c19a8f5.0403111003.540f2c4e@posting.google.com...
Hello -
I hope some database guru will enlighten me with this unique
situation. There appears to be significant overhead in encapsulating a
simple sql query in a stored procedure.
I have a simple procedure fsp_getstatus (@tradeid integer)
defined as:
declare @status_num decimal
If (Select count(trade_id) from trade_transaction where trade_id =
@TradeID) = 0
 set @status_num = -1
return @status_num
If I run the proc, it takes 30 ms. If i run the raw statements
(without the return of course), it takes 0 ms. This proc is called
hundreds of times by one of our other stored procedures, and this 30
ms delay (that has surfaced recently) is causing us severe performance
problems.
how much overhead is caused by running a stored procedure, compared to
a simple sql statement? Is there any reason why this overhead would
shoot up all of a sudden?
I could not find any help in documentation, hopefully some gurus can
enlighten me.
Thanks in advance
praty


Relevant Pages

  • Re: Error adding command properties for stored procedure call
    ... I see you are using the SQL Native Client for SQL Server ... A server cursor is not allowed on a remote stored procedure or stored ... The stored procedure called is a test one that simply SELECTs the name field ... int InitializeAndConnect; ...
    (microsoft.public.data.oledb)
  • Re: How to navigate recursive stored procedures results
    ... the identity is not "flow"ing to the SQL Server - that is - I'm using a single SQL account to access the SQL server for all the different users of the system. ... Also, I tried doing a union using my recursive procedure, but I can't union a SQL query and the results of a stored procedure. ... DECLARE @some_UID int, @parent_UID int, @ordering_attribute int ... > a recursive stored procedure and opt for using a temp. ...
    (microsoft.public.dotnet.framework.adonet)
  • Using MS Data Access application block to call stored procedure with parameters
    ... I am using SQL Server 2000 and ASP.NET 2.0 and want to call a stored ... My stored procedure has ... CustId (int), ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: stored procedure vs its equivalent SQL statement
    ... Try to call your stored procedure using parameter naming ... > In SQL Server 2000, if I run a stored procedure, ... > @relResID INT, ... > COMMIT TRANSACTION ...
    (microsoft.public.sqlserver.programming)
  • Re: How to get list of EventClasses in MSSQLServer2000
    ... statement inside a stored procedure has completed.') ... SQL Server statement or stored procedure.') ... Plan','Displays the plan tree of the Transact-SQL statement executed.') ... Login','Occurs when a SQL Server login is added or removed; ...
    (microsoft.public.sqlserver.security)