If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Database Server Software > Sybase > Delete operation on a big table

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 01-24-11, 18:10
regtha regtha is offline
Registered User
 
Join Date: Jan 2010
Posts: 72
Delete operation on a big table

Hi,

I have a table with 50 million records and have to delete 10 million records based on one condition. what is the best way to do this (without using much resources and also less time).

can we split those 10 million records and delete few at a time (say one million at a time).

Let me your ideas on this?
Reply With Quote
  #2 (permalink)  
Old 01-25-11, 02:54
pdreyer pdreyer is offline
Registered User
 
Join Date: May 2005
Location: South Africa
Posts: 1,268
Code:
declare @rowcnt int, @batchsize int
select @batchsize=1000000 -- Delete in batches of this amount
  ,@rowcnt=@batchsize
set rowcount @batchsize
while @rowcnt=@batchsize
begin 
  delete records where thedate<'20100101'
  set @rowcnt=@@rowcount
end
Reply With Quote
  #3 (permalink)  
Old 01-25-11, 08:54
regtha regtha is offline
Registered User
 
Join Date: Jan 2010
Posts: 72
Thanks for your reply.
Seems I confused. I would like to know what is the best way to delete.
Reply With Quote
  #4 (permalink)  
Old 01-28-11, 07:29
agrawal.meet agrawal.meet is offline
Registered User
 
Join Date: Jun 2010
Posts: 51
Assuming original table is table_1

How about:
1. Inserting the rest 40 million into a different table (use select * into).
2. Truncate and than drop the old table (table_1)
3. rename the table to table_1 created at step1
4. run sp_recompile table_1

Log usage will be minimal (in-fact if you do it rite, there will be no log usage) and operation will be much faster.
__________________
Please always reply to the post if it was helpful. Others may find it helpful.
Reply With Quote
  #5 (permalink)  
Old 01-31-11, 01:47
atish_amd atish_amd is offline
Registered User
 
Join Date: Jan 2011
Posts: 3
Delete operation on a big table

But truncate table is non log operation. If you want to recover the data from transaction log then it will not be possible.It will stop your dump transaction,if any scheduled. And you have to make dump database.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On