Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 Select and Update

Author  Topic 

rdaunce
Starting Member

7 Posts

Posted - 2005-09-30 : 14:37:38
I have a stored procedure with the following form:

ALTER PROCEDURE [dbo].sproc
@ID int = null
AS

If @ID Is Not Null
Begin

-- update the hitcounter for this
update table set counter = counter + 1 where ID = @ID

SELECT
[ID], [TypeID], [UserID], [Name], [Data], [Counter]
FROM [dbo].[table]
WHERE [ID] = @ID
End
Else
Begin
SELECT
[ID], [TypeID], [UserID], [Name], [Data], [Counter]
FROM [dbo].[table]

End
GO

This procedure has worked great for quite a long time. Today it started to take a long time to execute this procedure (15+ seconds). The only thing that has changed in this database is the actual data in the tables.

I was able to stop the slowdown by commenting out the UPDATE statement in the procedure. Once that was removed it started running great again. Does anyone have any idea why this might have started happening? Any suggestions on how to fix it or modify it so this doesn't occur? Thanks.


--Bob

nr
SQLTeam MVY

12543 Posts

Posted - 2005-09-30 : 15:46:49
Is ID indexed?
Could be you need to update statistics or the update was being blocked.


==========================================
Cursors are useful if you don't know sql.
DTS can be used in a similar way.
Beer is not cold and it isn't fizzy.
Go to Top of Page
   

- Advertisement -