Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

is insert into.. select statement transactional?

do i need to use transaction to provide all or not proposition for the following insert process?

INSERT INTO table1 ( column1 , column2)
SELECT  col1, col2
FROM    table2  

expecting average row-count from table2 is around 150 and target database is ms sql server 2008 r2.

like image 1000
Adam Right Avatar asked Oct 16 '25 23:10

Adam Right


1 Answers

No, you don't need to. A single SQL statement is already in a transaction by default so there is no way that you will partually insert results or that results will be meanwhile moderated by another transaction. The fact that 2 tables are involved doesn't change the fact that a single SQL statement is used.

like image 62
Ivaylo Toskov Avatar answered Oct 19 '25 12:10

Ivaylo Toskov