Deleting 3 millon duplicated records from 4 million records

Hi,
I want to delete 3 million duplicate records from 4 million records in production. We dont have the partitions. I cann't recreate table using CTAS Option. So I have to delete the data in batch because of shared environment and people acceessing the data.
Is there any fastest way to delete the data in stead of using bulk delete by using max rowid.
please help me out.
Regards,
Venkat.
Edited by: ramanamadhav on Aug 16, 2011 8:41 AM

After deletion of data( with suggestion given by Justin), make sure that latest statistics are also taken.
After such a heavy delete there is always a mismatch between num_rows and actual count.
the best way is to shrink space and then gather table statistics, other wise optimizer will get confused and it will not take into consideration correct statistics.
For e.g.
16:41:55 SQL> create table test_tab_sm
as
select level col1, rpad('*888',200,'###') col2
from dual connect by level <= 100000;16:42:05   2  16:42:05   3  16:42:05   4 
Table created.
Elapsed: 00:00:00.49
16:42:08 SQL> exec dbms_stats.gather_table_stats(ownname => 'KDM', tabname => 'TEST_TAB_SM', cascade => true);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.51
16:42:17 SQL> select table_name,num_rows,blocks,avg_row_len,chain_cnt from user_tables where table_name = 'TEST_TAB_SM';
TABLE_NAME                       NUM_ROWS     BLOCKS AVG_ROW_LEN  CHAIN_CNT
TEST_TAB_SM                        100000       2942         205          0
1 row selected.
Elapsed: 00:00:00.01
16:42:28 SQL> delete from TEST_TAB_SM where mod(col1,2) =1;
50000 rows deleted.
Elapsed: 00:00:01.09
16:42:39 SQL> select table_name,num_rows,blocks,avg_row_len,chain_cnt from user_tables where table_name = 'TEST_TAB_SM';
TABLE_NAME                       NUM_ROWS     BLOCKS AVG_ROW_LEN  CHAIN_CNT
TEST_TAB_SM                        100000       2942         205          0
1 row selected.
Elapsed: 00:00:00.01
16:42:47 SQL> exec dbms_stats.gather_table_stats(ownname => 'KDM', tabname => 'TEST_TAB_SM', cascade => true);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.26
16:42:55 SQL> select table_name,num_rows,blocks,avg_row_len,chain_cnt from user_tables where table_name = 'TEST_TAB_SM';
TABLE_NAME                       NUM_ROWS     BLOCKS AVG_ROW_LEN  CHAIN_CNT
TEST_TAB_SM                         50000       2942         205          0
1 row selected.
Elapsed: 00:00:00.01
16:43:27 SQL> alter table TEST_TAB_SM move;
Table altered.
Elapsed: 00:00:00.46
16:43:59 SQL>  select table_name,num_rows,blocks,avg_row_len,chain_cnt from user_tables where table_name = 'TEST_TAB_SM';
TABLE_NAME                       NUM_ROWS     BLOCKS AVG_ROW_LEN  CHAIN_CNT
TEST_TAB_SM                         50000       2942         205          0
1 row selected.
Elapsed: 00:00:00.03
16:44:06 SQL> exec dbms_stats.gather_table_stats(ownname => 'KDM', tabname => 'TEST_TAB_SM', cascade => true);
PL/SQL procedure successfully completed.
Elapsed: 00:00:00.24
16:44:17 SQL> select table_name,num_rows,blocks,avg_row_len,chain_cnt from user_tables where table_name = 'TEST_TAB_SM';
TABLE_NAME                       NUM_ROWS     BLOCKS AVG_ROW_LEN  CHAIN_CNT
TEST_TAB_SM                         50000       1471         205          0
1 row selected.
Elapsed: 00:00:00.01
16:44:24 SQL> We can see how the no. of blocks changes. It changed from 2942 to 1471 which is half and in your case it will be 1/4th times of what it was using.
There are other options for shrinking space as well other than MOVE.
alter table <table_name> shrink space;Try it out and you can see the difference yourself.

Similar Messages

  • How to delete the duplicated records, not just surpress the records?

    I am new to CR. Right now I am doing a project which needs CR get query from Oracle. I got the query from Oracle. There are records with duplicated fields. For example (the following only show part of fields):
    ID    body_code  
    1            10            
    2             10            
    3             15            
    4              15           
    5              15           
    6              16           
    I need to only select records (not surpress, because I will do some caluculate later) like following:
    ID         body_code        
    1             10         
    2              15
    3               16   
    I tried to creat selection fomula in fomula workshop, shown as follows:
    onlastrecord;
    <>next
    but CR said next can be evaluated. I think it must have something to do with the print-time. So what show I do to delete the duplicated records.Thank you very much.

    Ting,
    Try this:
    Insert a group on body_code.  Then create a running total called Distinct Count.  Field to summarize -> ID, Evaluate on change of group Group # 1 Body Code, and Never Reset.
    Then insert a chart in the report header:
    In the advanced layout, select body_code on change of and select Distinct Count running total in the Show values.
    I hope I understood what you're looking to accomplish.
    Z

  • Deleting duplicated records by date

    Hi,
    what could I do to delete duplicated records from test1 table
    the test1 table have the next columns that I describe below:
    code
    operator
    phone
    init_date
    end_date The records are duplicated by code, operator, phone, init_date
    and I need to delete the records with min(end_date)
    thanks in advanced...

    /* Formatted on 1/12/2012 7:28:44 AM (QP5 v5.149.1003.31008) */
    CREATE TABLE data
    AS
       (SELECT 'A' code,
               'Bob' operator,
               '111-2222' phone,
               ADD_MONTHS (SYSDATE, -1) init_date,
               SYSDATE end_date
          FROM DUAL
        UNION ALL
        SELECT 'A',
               'Bob',
               '111-2222',
               ADD_MONTHS (SYSDATE, -1) init_date,
               SYSDATE + 1 end_date
          FROM DUAL);
    DELETE FROM data
          WHERE (code, operator, phone, init_date, end_date) IN
                   (SELECT code,
                           operator,
                           phone,
                           init_date,
                           end_date
                      FROM (SELECT data.*,
                                   COUNT (
                                   OVER (
                                      PARTITION BY code,
                                                   operator,
                                                   phone,
                                                   init_date)
                                      cnt,
                                   ROW_NUMBER ()
                                   OVER (
                                      PARTITION BY code,
                                                   operator,
                                                   phone,
                                                   init_date
                                      ORDER BY end_date)
                                      rn
                              FROM data)
                     WHERE cnt > 1 AND rn = 1);

  • Deletion of  a particular record  from database table

    hai friends,
         i want to <b>delete</b> (or)   <b>insert</b> particular record from  predefined sap table... that is with out module pool programming...  can i delete or insert a record to or from  the table..
         thanks in advance
    @jay

    hi,
    ucan do it without module pool programming in your normal report program.
    To insert a line into an index table, use the statement:
    INSERT <line> INTO <itab> [INDEX <idx>].
    <line> is either a work area that is convertible to the line type, or the expression INITIAL LINE. If you use <wa>, the system adds a new line to the internal table <itab> and fills it with the contents of the work area. INITIAL LINE inserts a blank line containing the correct initial value for each field of the structure.
    To select the lines that you want to delete using a condition, use the following:
    DELETE FROM <target> WHERE <cond> .
    All of the lines in the database table that satisfy the conditions in the WHERE clause are deleted. The FROM expression must occur between the keyword and the database table.
    You should take particular care when programming the WHERE clause to ensure that you do not delete the wrong lines. For example, if you specify an empty internal table in a dynamic WHERE clause, all of the lines in the table are deleted.
    If at least one line is deleted, the system sets SY-SUBRC to 0, otherwise to 4. SY-DBCNT contains the number of lines deleted.
    regards,
    keerthi

  • How can I delete Duplicated icon from the dashboar

    Please can someone help me : How do I  delete duplicated icon from dashboard, like the  Safari Icon and System Preference, and remain witht only one of each, that keeps working?  Thank you

    Well, Aleksdev and Paul_31, you helped me a lot, , thank you so much.
    Let me tell what worked.
    I went to the dock and deleted the good Safari and System icons, then I draged the ones on the dashboard to the trash.
    Then I restarted,  and they were no more either on the dock nor on dashboard.
    To put the safari icon back to the dock, I had to go Applications and drag the Safari Icon back to the dock. It worked, but with the icon for System Preferences, it did nit work this way.
    But never mind the important is that Safari icon stays always at the dock .
    So, one more time, guys thank you so much for the help.
    Maybe I'll be asking some more questions in the future, if you don't mind. I'm not an I-MAC specialist. I'm new on Apple world.
    Best regards!
    Monica

  • Delete a Material Master Record Permanently from R/3 4.7

    We have a requirement to delete certain material master records permanently from our R/3 4.7 system. We have already archived all the relevant material master documents using SARA and are now trying to delete the material permanently using SARA but are unable to do so as the program is finding archive entries in MARI and prevents the material from being permanently deleted.
    Is there a way to remove records from MARI so that we can delete the material master record permanently.
    Thanks in advance.
    Samir

    It looks like transaction MMDE cannot be used for deleting only a certain set of materials. It is setup to delete all the materials.
    Is there a way to delete only a certain set of materials permanently from the client?
    Thanks
    Samir

  • The load from ODS - 0FIAP_O03 to cube 0FIAP_C03  is duplicating records

    Hello Everyone
    I need some help/advice for the following issue
    SAP BW version 3.5
    The Delta load for ODS - 0FIAP_O03 works correctly
    The load from ODS - 0FIAP_O03 to cube 0FIAP_C03  is duplicating records
    NB Noticed one other forum user who has raised the same issue but question is not answered
    My questions are 
    1. Is this a known problem?
    2. Is there a fix available from SAP?
    3. If anyone has had this issue and fixed it, could you please share how you achieved this
    i have possible solutions but need to know if there is a standard solution
    Thankyou
    Pushpa

    Hello Pushpa,
    I assume that you are using the Delta load to the initial ODS and then to the CUBE as well.
    If the Delta is placed in both the places then there should not be any issue while sending the data to CUBE.
    If you are using the FULL Load then normally the data will gets aggregated in the cube as objects are with the Addition mode in the Cube.
    Can you post the exact error that you are facing here as this also can be of the design issue.
    Murali

  • How to delete fixed number of records at a time

    Hi,
    I have a millions of records in one table.I have to purge first 15 days data per day by deleting at time 10000 records.
    Appreciate any ideas from you.
    Thanks in Advance.
    regards,
    Suresh

    Hi,
    I have a millions of records in one table.I haveto
    purge first 15 days data per day by deleting attime
    10000 records.
    Appreciate any ideas from you.
    Obviously you will need a timestamp.I have one column which will have record created time
    Why would you limit it to 10,000 at a time?I am using oracle 9i as back end.My requirement is not to delete more than 10000 at a time as load will be very high on this table.

  • What is the best practice of deleting large amount of records?

    hi,
    I need your suggestions on best practice of deleting large amount of records of SQL Azure regularly.
    Scenario:
    I have a SQL Azure database (P1) to which I insert data every day, to prevent the database size grow too fast, I need a way to  remove all the records which is older than 3 days every day.
    For on-premise SQL server, I can use SQL Server Agent/job, but, since SQL Azure does not support SQL Job yet, I have to use a Web job which scheduled to run every day to delete all old records.
    To prevent the table locking when deleting too large amount of records, in my automation or web job code, I limit the amount of deleted records to
    5000 and batch delete count to 1000 each time when calling the deleting records stored procedure:
    1. Get total amount of old records (older then 3 days)
    2. Get the total iterations: iteration = (total count/5000)
    3. Call SP in a loop:
    for(int i=0;i<iterations;i++)
       Exec PurgeRecords @BatchCount=1000, @MaxCount=5000
    And the stored procedure is something like this:
     BEGIN
      INSERT INTO @table
      SELECT TOP (@MaxCount) [RecordId] FROM [MyTable] WHERE [CreateTime] < DATEADD(DAY, -3, GETDATE())
     END
     DECLARE @RowsDeleted INTEGER
     SET @RowsDeleted = 1
     WHILE(@RowsDeleted > 0)
     BEGIN
      WAITFOR DELAY '00:00:01'
      DELETE TOP (@BatchCount) FROM [MyTable] WHERE [RecordId] IN (SELECT [RecordId] FROM @table)
      SET @RowsDeleted = @@ROWCOUNT
     END
    It basically works, but the performance is not good. One example is, it took around 11 hours to delete around 1.7 million records, really too long time...
    Following is the web job log for deleting around 1.7 million records:
    [01/12/2015 16:06:19 > 2f578e: INFO] Start getting the total counts which is older than 3 days
    [01/12/2015 16:06:25 > 2f578e: INFO] End getting the total counts to be deleted, total count:
    1721586
    [01/12/2015 16:06:25 > 2f578e: INFO] Max delete count per iteration: 5000, Batch delete count
    1000, Total iterations: 345
    [01/12/2015 16:06:25 > 2f578e: INFO] Start deleting in iteration 1
    [01/12/2015 16:09:50 > 2f578e: INFO] Successfully finished deleting in iteration 1. Elapsed time:
    00:03:25.2410404
    [01/12/2015 16:09:50 > 2f578e: INFO] Start deleting in iteration 2
    [01/12/2015 16:13:07 > 2f578e: INFO] Successfully finished deleting in iteration 2. Elapsed time:
    00:03:16.5033831
    [01/12/2015 16:13:07 > 2f578e: INFO] Start deleting in iteration 3
    [01/12/2015 16:16:41 > 2f578e: INFO] Successfully finished deleting in iteration 3. Elapsed time:
    00:03:336439434
    Per the log, SQL azure takes more than 3 mins to delete 5000 records in each iteration, and the total time is around
    11 hours.
    Any suggestion to improve the deleting records performance?

    This is one approach:
    Assume:
    1. There is an index on 'createtime'
    2. Peak time insert (avgN) is N times more than average (avg). e.g. supposed if average per hour is 10,000 and peak time per hour is 5 times more, that gives 50,000. This doesn't have to be precise.
    3. Desirable maximum record to be deleted per batch is 5,000, don't have to be exact.
    Steps:
    1. Find count of records more than 3 days old (TotalN), say 1,000,000.
    2. Divide TotalN (1,000,000) with 5,000 gives the number of deleted batches (200) if insert is very even. But since it is not even and maximum inserts can be 5 times more per period, set number of deleted batches should be 200 * 5 = 1,000.
    3. Divide 3 days (4,320 minutes) with 1,000 gives 4.32 minutes.
    4. Create a delete statement and a loop that deletes record with creation day < today - (3 days ago - 3.32 * I minutes). (I is the number of iterations from 1 to 1,000)
    In this way the number of records deleted in each batch is not even and not known but should mostly within 5,000 and even you run a lot more batches but each batch will be very fast.
    Frank

  • Duplicated records on infoobect data load

    Hi,
    I have a problem when loading dato to 0UCINSTALLA infoobject.
    It goes to Red flga and It reports duplicated records in /BI0/QUCINSTALLA and /BI0/YUCINSTALLA tables.
    I checked the infopackage and the "PSA only" checkbox is selected, and "Continuing..." and "Ingnore dup records" checkboxes are selected, too.
    If the "Ignore duplicated records" is selected, why is reporting the error?
    I don't know what to do with this problem.
    any ideas?
    thanks for the help.
    Mauricio.

    In transfer structure write a start routine that delete duplicate record like that:
    sort DATAPAK by /BIC/filed1 descending /BIC/filed2
    /BIC/filed3.
    delete adjacent duplicates from DATAPAK comparing /BIC/filed1 /BIC/filed2.
    Hope it helps.
    Regards

  • How can I delete my photos in streaming from iCloud?

    How can I delete my photos in streaming from iCloud? Thank you.

    Look, there are a million threads on this already. 
    The facts are:
    1) you can't delete individuals photos from Photostream. Simple as that.
    2) if you want to delete all the photos, then switch PS off on all your devices (including iPhoto), go to iCloud.com, click on your name, go to advanced settings and reset PS.  They will be gone from all your devices and iCloud.
    3) switch PS back on in all the same devices.
    Let's hope this is sorted out in the near future.

  • Best way to delete large number of records but not interfere with tlog backups on a schedule

    Ive inherited a system with multiple databases and there are db and tlog backups that run on schedules.  There is a list of tables that need a lot of records purged from them.  What would be a good approach to use for deleting the old records?
    Ive been digging through old posts, reading best practices etc, but still not sure the best way to attack it.
    Approach #1
    A one-time delete that did everything.  Delete all the old records, in batches of say 50,000 at a time.
    After each run through all the tables for that DB, execute a tlog backup.
    Approach #2
    Create a job that does a similar process as above, except dont loop.  Only do the batch once.  Have the job scheduled to start say on the half hour, assuming the tlog backups run every hour.
    Note:
    Some of these (well, most) are going to have relations on them.

    Hi shiftbit,
    According to your description, in my opinion, the type of this question is changed to discussion. It will be better and 
    more experts will focus on this issue and assist you. When delete large number of records from tables, you can use bulk deletions that it would not make the transaction log growing and runing out of disk space. You can
    take the table offline for maintenance, a complete reorganization is always best because it does the delete and places the table back into a pristine state. 
    For more information about deleting a large number of records without affecting the transaction log.
    http://www.virtualobjectives.com.au/sqlserver/deleting_records_from_a_large_table.htm
    Hope it can help.
    Regards,
    Sofiya Li
    Sofiya Li
    TechNet Community Support

  • The correct way to delete old transport request record ?

    Dear all,
    We want to delete old transport request record before 2008 (two years before) of our system.
    We learn that we should delete the records in the below two path:
    /usr/sap/trans/data
    /usr/sap/trans/cofiles
    Our target is that we will not see the old record after deleting in our PRD system.
    Normally, we see the transport request record in system by this way:
    STMS -->  import overview --> PRD --> Import Queue   system PRD --> Import history
    Our question is do we need to restart our system after delete the record to refresh the Import history?
    We have not delete the record now.
    Any experienced or expert, please kindly give advice.
    Regards,
    Allen

    Hello Allen,
    there are some notes and documentations for this process. Deleting the files from /cofiles and /data will not erase the request from the import history, as you already know.
    You should follow note #41732 to have the requests/data completely deleted from your system. There is a lot of complementary reading in notes #7224, #556734, #189841, etc.
    Note that you can remove the request from the import queue, import history, data and cofiles subdirectory, but still have it on the <SID> buffer (located in  /usr/sap/trans/buffer/<SID>). If this happens to you, please save a copy of the buffer file <SID>, then create a new, blank file named <SID> at a time when the import queue is empty (VERY IMPORTANT). Or, alternatively, please excute the tp cleanbuffer FIL command (which will erase the requests that are not found in /data and /cofiles directories).
    --> Please test this first on a test system, not directly on a productive environment.
    This should be enough to delete old transport requests on your system.
    Best regards,
    Tomas Black

  • How can I get rid of duplicated tracks from my iPhone?

    Hello! I recently acquired an iPhone and have been adding albums to it from my iTunes library. I then started adding artwork to my albums on my iTunes library to make it look more interesting upon playback. However, this has somehow resulted in many tracks being duplicated on my iPhone - even though no duplicated tracks can be seen in my iTunes library for me to unclick and try to resolve manually. My playlists in iTunes appear tidy, and have been re-synching these along with the newly acquired artwork to my iPhone. But everytime I do this it just adds more and more duplicated tracks to my iPhone. I am becoming frustrated. Is there any way I can get rid of these duplicated tracks from my iPhone without deleting my iTunes library?

    remove them from your playlists in iTunes and then sync.

  • Deleting all the similar records except one

    I have a table without a primary/unique key, this table contains too many rows that have the same column values(the row is duplicated), How can I delete all the duplicated rows and keep one copy of this rows?

    <BLOCKQUOTE><font size="1" face="Verdana, Arial, Helvetica">quote:</font><HR>Originally posted by Waleed Dallah ([email protected]):
    I have a table without a primary/unique key, this table contains too many rows that have the same column values(the row is duplicated), How can I delete all the duplicated rows and keep one copy of this rows?<HR></BLOCKQUOTE>
    Hi
    This query may be solev ur problem
    delete table where rowid not in(select min(rowid) from table1 group by fieldname)
    This query if u want to keep latest row use max(rowid) instead of min(rowid)
    let me know
    by
    venkat
    ([email protected])

Maybe you are looking for

  • Z1-015 Error "Enter Business Area" in BAPI_INCOMINGINVOICE_CREATE

    Hi All,<br/><br/> Here is a scenario that has totally confused me and I don't know what to do. Any guidance in this area will be highly appreciated.<br/><br/> I am using BAPI BAPI_INCOMINGINVOICE_CREATE for MIRO. Our client gets invoices that contain

  • ITunes plays songs in the wrong order

    For the past few weeks iTunes has insisted on jumping all over the place when playing songs. It plays randomly, but only from the same artist. If I'm playing an album, it doesn't go automatically from track 1 to 2, but seems to select the next track

  • How do I manage my websites from my Azure trial?

    A long time ago, I signed up for the azure trial that came with 10 free asp.net web sites (http://azure.microsoft.com/en-us/develop/net/aspnet/). I only tried it with a single site, but it worked well enough that I had eventually planned to use it fo

  • Reservation of Stock during MD50 run

    Dear Sir, We have a make-to-order scenario . We run MRP using MD50 , and MRP is run against a Sale-Order & it's Line Item . Our problem is that during MRP run , System is not reserving the Stock Items available under the un-restricted own's stock . 

  • HT2311 update to itunes 10.7

    i have updated to iphone 5 when i have plugged into itunes it tells me i have to pdate to itunes7 , but when i try to update my mac it tells me i cannot update from 10.5.8 to 10.6.8 !!!!!! help