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.
| Author |
Topic |
|
javelin
Starting Member
1 Post |
Posted - 2006-02-24 : 23:42:57
|
| I am running the following stored procedure toset values in the same tables and also insert the current fetch in another table.I am running this across 5 million rows approx (10 million on two tables when joined).I am also using clustered index on the two set of tables but the performance is still slow.CREATE procedure dbo.reconcilemod2 asDECLARE @subno varchar(20), @b_subno varchar(20), @transdatec datetime, @durp varchar(10), @durc varchar(10),@transdatep datetimeDECLARE C1 cursor FORWARD_ONLY forselect warid.subno , warid.b_subno , warid.transdate, tel.transdate ,warid.act_duration , tel.act_durationfrom iaa_histcalls_cur warid ,iaa_histcalls_prov tel where warid.subno=tel.subnoand warid.b_subno=tel.b_subnoand warid.flex_fld1 is null and tel.flex_fld1 is nulland abs(datediff( mi,tel.transdate , warid.transdate))<7 FOR UPDATE OF tel.flex_fld1,warid.flex_fld1WHILE @@FETCH_STATUS = 0BEGINopen c1fetch NEXT FROM c1 into @subno,@b_subno,@transdatec,@transdatep,@durc,@durpbeginupdate iaa_histcalls_prov set flex_fld1 = 'P' where current of c1update iaa_histcalls_cur set flex_fld1 = 'P' where current of c1insert into dbo.recons_duration_exc (subno, b_subno,transdatep,durp, durc, transdatec ) values (@subno,@b_subno,@transdatep,@durp,@durc,@transdatec)endendclose c1deallocate c1GOAny help Please |
|
|
jonasalbert20
Constraint Violating Yak Guru
300 Posts |
Posted - 2006-02-25 : 01:25:34
|
| i have read an article about using a cursor...http://www.extremeexperts.com/sql/articles/BestPractices.aspx2. Avoid using cursorsUse cursors wisely. Cursors are fundamentally evil. They force the database engine to repeatedly fetch rows, negotiate blocking, manage locks, and transmit results. They consume network bandwidth as the results are transmitted back to the client, where they consume RAM, disk space, and screen real estate. Consider the resources consumed by each cursor you build and multiply this demand by the number of simultaneous users.http://www.sql-server-performance.com/vk_sql_best_practices.aspTry to avoid server side cursors as much as possible. Always stick to a 'set-based approach' instead of a 'procedural approach' for accessing and manipulating data.hope it gives information.Want Philippines to become 1st World COuntry? Go for World War 3... |
 |
|
|
Kristen
Test
22859 Posts |
Posted - 2006-02-25 : 02:12:04
|
| Hi javelin, Welcome to SQL Team!Can't you just update iaa_histcalls_prov and iaa_histcalls_cur by joining them to the tables in the SELECT you are using in your Cursor definition? and then use a similar join to make the INSERT into recons_duration_exc?I'll give you good odds that this will be an order of magnitude faster than using a cursor!You ought to also put a transaction block around this (whether you stick with the cursor or a Set Based method) so that it is rolled back when it fails.Kristen |
 |
|
|
|
|
|
|
|