How do I LIMIT the number of rows in a DELETE with DB2?

后端 未结 9 548
醉梦人生
醉梦人生 2021-01-11 17:09

I want to add a security on a sensitive table when I delete lines with an SQL request on a DB2 table.

I want to mimic the way MySQL allows you to limit the numbers o

相关标签:
9条回答
  • 2021-01-11 17:48

    Just select a statement, and put the statement inside the delete query:

    delete from (
    select from table WHERE info = '1' order by id fetch first 25000 rows only
    )
    
    0 讨论(0)
  • 2021-01-11 17:50
    delete from table where id in (select id from table where info = '1' order by id fetch first 1 rows only)
    
    0 讨论(0)
  • 2021-01-11 17:50
    MERGE INTO XYZ A<BR>
    USING (<BR>
    SELECT RID_BIT(B) CHAVE<BR>
    FROM XYZ B<BR>
    FETCH FIRST 100000 ROWS ONLY) B<BR>
    ON RID_BIT(A) = B.CHAVE<BR>
    WHEN MATCHED THEN DELETE;
    
    0 讨论(0)
  • 2021-01-11 17:59

    If your primary key has multiple values, or you just need multiple values as the condition, this is the query that works:

    DELETE FROM TABLE
    WHERE (COLUMN1, COLUMN2) IN (
        SELECT COLUMN1, COLUMN2 FROM TABLE
        WHERE SOME_COLUMN='THIS'
        AND SOME_OTHER_COLUMN LIKE 'THAT%'
        FETCH FIRST 10 ROWS ONLY)
    
    0 讨论(0)
  • 2021-01-11 18:00

    How is this query?

    delete from table D where exists 
     ( select * from ( select * from table M fetch first 10 rows only ) as M
       where M.object_id = D.object_id )
    
    0 讨论(0)
  • 2021-01-11 18:04
    DELETE                                      
    FROM Bibl/File                             
    WHERE RRN(File) =  (                        
                        SELECT min(RRN(File))   
                        FROM Bibl/File         
                        WHERE Fld1 = 'xx'     
                       )   
    

    The RRN function is to AS400/iSeries/PowerSystem alone. In other environments there are other functions for the relative record number.

    This makes it possible to erase a record of several identical even without UNIQUE key. It can also be used to update with minor changes.

    works like the LIMIT but with DELETE and / or UPDATE.

    It only works on SQL DB2 in other settings should be changed by RRN function to return the column number

    0 讨论(0)
提交回复
热议问题