RE: slow server response
From: mark h (h_at_discussions.microsoft.com)
Date: 07/08/04
- Next message: Aaron [SQL Server MVP]: "Re: remove identity column"
- Previous message: Steve Kass: "Re: Need help in writing a faster query"
- In reply to: saif: "slow server response"
- Next in thread: saif: "Re: slow server response"
- Reply: saif: "Re: slow server response"
- Messages sorted by: [ date ] [ thread ]
Date: Thu, 8 Jul 2004 09:24:03 -0700
The general rule is to use cursors and temp tables as seldom as possible. They both cause the affects you are experiencing, poor performance. The reason is simple a cursor creates a copy of the table in memory, in your case a million records. It takes time to move that many records into memory. In addition,depending on the type of cursor you define there is a lot of over head in managing them. Try to use forward only if you must use a cursor.
If you come to SQL from a procedural background you're use to working record by record but in SQL you work in sets. Most uses of cursors and temp tables can be reprogrammed to use set therory.
"saif" wrote:
> Hi
>
> I have created a stored procedure which reads results from a table using
> cursor and then inserts those results in a temp table. When i run this
> stored procedure in query analyzer, it runs fine but takes too long
> returning results. This stored procedure extracts data from a table that has
> more than 1000000 records. Now confusion is that when i created this stored
> procedure and used it for first time, results were returned quickly but now
> its taking too long. Why is this happening? Is there any solution to this
> problem? Somebody told me to use indexes! Please give me some urls from
> where i can get help about indexes. I am new to sql programming. I shall be
> thankful.
>
> Regards
>
> Saif
>
>
>
- Next message: Aaron [SQL Server MVP]: "Re: remove identity column"
- Previous message: Steve Kass: "Re: Need help in writing a faster query"
- In reply to: saif: "slow server response"
- Next in thread: saif: "Re: slow server response"
- Reply: saif: "Re: slow server response"
- Messages sorted by: [ date ] [ thread ]
Relevant Pages
|