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)
 optimize deletion in sql server 2000

Author  Topic 

alejo46
Posting Yak Master

157 Posts

Posted - 2012-07-04 : 21:14:54
Good evening

I've got a simple deletion like this:

delete from tablex
where start_date >= '20120101'
and start_date < = '20120131'

i known optimization depends from some factors like index, the table size and so on,
but this script initially was implemented in batch using the set rows ....

I've been said that executing the deletion directly (no batch) is faster than in batch, its true or false ? and why ?



visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-04 : 23:56:32
it depends on the size of dataset. how big is your data as returned by above query?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

alejo46
Posting Yak Master

157 Posts

Posted - 2012-07-05 : 11:17:44
it must return about 67 millions of rows affected
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-05 : 11:42:30
do you've too many indexes on table? also is table partitioned?

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

alejo46
Posting Yak Master

157 Posts

Posted - 2012-07-05 : 12:30:57
the table is not partitionated, and this table have some indexes and the start_date field has index too.
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2012-07-05 : 12:35:33
see estimated execution plan and identify costly steps in deletion query.

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page

robvolk
Most Valuable Yak

15732 Posts

Posted - 2012-07-05 : 13:13:25
You're trying to delete 67 million rows, how many rows do you need to keep in the table?
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-05 : 14:18:29
Yes it runs faster as a one big batch than in smaller batches. But that's the whole point of doing it in small batches: to slow it down. You are minimizing blocking by doing it in small batches.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

tkizer
Almighty SQL Goddess

38200 Posts

Posted - 2012-07-05 : 14:53:51
I should add that doing a large delete in small batches also is done to minimize transaction log size.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page
   

- Advertisement -