SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 SQL Server 2000 Forums
 Transact-SQL (2000)
 optimize deletion in sql server 2000
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

alejo46
Yak Posting Veteran

Colombia
80 Posts

Posted - 07/04/2012 :  21:14:54  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 07/04/2012 :  23:56:32  Show Profile  Reply with Quote
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
Yak Posting Veteran

Colombia
80 Posts

Posted - 07/05/2012 :  11:17:44  Show Profile  Reply with Quote
it must return about 67 millions of rows affected
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

India
47069 Posts

Posted - 07/05/2012 :  11:42:30  Show Profile  Reply with Quote
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
Yak Posting Veteran

Colombia
80 Posts

Posted - 07/05/2012 :  12:30:57  Show Profile  Reply with Quote
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

India
47069 Posts

Posted - 07/05/2012 :  12:35:33  Show Profile  Reply with Quote
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

USA
15559 Posts

Posted - 07/05/2012 :  13:13:25  Show Profile  Visit robvolk's Homepage  Reply with Quote
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

USA
35007 Posts

Posted - 07/05/2012 :  14:18:29  Show Profile  Visit tkizer's Homepage  Reply with Quote
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

Edited by - tkizer on 07/05/2012 14:18:58
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
35007 Posts

Posted - 07/05/2012 :  14:53:51  Show Profile  Visit tkizer's Homepage  Reply with Quote
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
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.06 seconds. Powered By: Snitz Forums 2000