INSERT SELECT Statement and Rollback SQL

Posted by Juan Perez on Stack Overflow See other posts from Stack Overflow or by Juan Perez
Published on 2010-06-15T20:57:24Z Indexed on 2010/06/15 21:12 UTC
Read the original article Hit count: 212

Filed under:
|
|

Im Working on a creation of a query who uses INSERT SELECT statement using MS SQL Server 2008:

INSERT INTO TABLE1 (col1, col2) SELECT col1, col2 FROM TABLE2

Right now the excecution of this query is inside a transaction:

Pseudocode:

try  
{  
    begin transaction;  
    query;  
    commit;  
}  
catch
{
rollback; 
}

If TABLE2 has around 40m of rows, at the moment of making the insert on the TABLE1, if there is an error in the middle of the INSERT, will the INSERT SELECT statement make a rollback itself or I need to use a transaction to preserve data integrity?

It is necessary to use a transaction? or SQL SERVER it self uses a transaction for this type of sentences.

© Stack Overflow or respective owner

Related posts about c#

Related posts about sql