Canceling an INSERT statement

  • I'm not clear on something

    If I run a big insert job of 100,000 records

    INSERT into TableB

    select * from TableA

    But while it's running in a query window, I press cancel.

    It says "Canceling Query", then "query canceled"

    Will it rollback the insert ?

    I tried it in a test case, and none were inserted, but not sure if that's a predictable result.

  • Yes - it will roll back the transaction that was in process when you cancelled the insert.

    Jeffrey Williams
    “We are all faced with a series of great opportunities brilliantly disguised as impossible situations.”

    ― Charles R. Swindoll

    How to post questions to get better answers faster
    Managing Transaction Logs

  • If you are unsure of the result you could always wrap the statement in a transaction. That would ensure that if it was cancelled it would be rolled back.

    Joie Andrew
    "Since 1982"

  • Yes, as Jeffrey mentioned, it would rollback the insert. Rollback would also take some time depending on the # of records it has processed..


    Bru Medishetty

    Blog -- LearnSQLWithBru

    Join on Facebook Page Facebook.comLearnSQLWithBru

    Twitter -- BruMedishetty

  • And with the rollback, you must wait it out.

    Jason...AKA CirqueDeSQLeil
    _______________________________________________
    I have given a name to my pain...MCM SQL Server, MVP
    SQL RNNR
    Posting Performance Based Questions - Gail Shaw[/url]
    Learn Extended Events

  • But the log file will keep grow to accomadate both the insert and the delete.

    Regards

    Akhil

  • Yes Sql Server rollback all the process.

    Regards

    Irshad Vaza

  • You can cancell. But depending on batch size of insert the rol lback take time.

  • Joie Andrew (2/4/2010)


    If you are unsure of the result you could always wrap the statement in a transaction. That would ensure that if it was cancelled it would be rolled back.

    No need. An insert is always in a transaction, regardless of whether one is explicitly created or not and SQL will always roll back an uncompleted transaction.

    Gail Shaw
    Microsoft Certified Master: SQL Server, MVP, M.Sc (Comp Sci)
    SQL In The Wild: Discussions on DB performance with occasional diversions into recoverability

    We walk in the dark places no others will enter
    We stand on the bridge and no one may pass

Viewing 9 posts - 1 through 8 (of 8 total)

You must be logged in to reply to this topic. Login to reply