简体   繁体   中英

How to speed up the delete operation from a table that has millions of records?

 BEGIN TRANSACTION
   BEGIN TRY 
      ;WITH CTE_TQUOTEWO
          AS
          (
            SELECT WORKID,QUOTE_NO
            FROM ABC_TQUOTEWO WITH(INDEX(PK_TQUOTEWO_ID))
            WHERE TQUOTEWO_ID != '' 
          )
        DELETE CA
        FROM CTE_TQUOTEWO CA  
        JOIN I_ABC_TQUOTEWO AT WITH(INDEX(PK_ITQUOTEWO_ID))
        ON AT.WORKID = CA.WORKID
        AND AT.QUOTE_NO = CA.QUOTE_NO
        AND AT.TQUOTEWO_ID != '';
     COMMIT TRANSACTION
   END TRY
   BEGIN CATCH
    ROLLBACK TRANSACTION
   END CATCH

I have a table with millions of records and no indexes defined on it, still it takes much time for execution. Can anyone suggest to do the delete operation much faster? using sql server...

If you need to delete all rows.

USE EXTRA CARE....And i mean EXTRA because i have used it on a table that i dind't want to delete ALL rows. Thankfully it was on a test environment.

SQL TRUNCATE

如果不需要登录,则可以使用“ 截断”

TRUNCATE TABLE TableName;

截断应比

DELETE FROM TableName;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM