Please start any new threads on our new site at We've got lots of great SQL Server experts to answer whatever question you can come up with.

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 SQL Server 2012 Forums
 Transact-SQL (2012)
 Multiple inserts in one table. Union or not?
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Yak Posting Veteran

52 Posts

Posted - 02/21/2014 :  04:01:39  Show Profile  Reply with Quote
Hi all,

I have a query which inserts data from different sources into one table. Now it's like this:

Insert into tab
select *
from source_tab_a

Insert into tab
select *
from source_tab_b

Insert into tab
select *
from source_tab_c

I'm wondering which is better, the above separate insert query's or the following:

insert into tab
select * from source_tab_a
union all
select * from source_tab_b
union all
select * from source_tab_c

Can somebody explain?


James K
Flowing Fount of Yak Knowledge

3873 Posts

Posted - 02/21/2014 :  15:17:21  Show Profile  Reply with Quote
If it is a small number of rows that gets inserted it wouldn't matter which method you used. If you have a large number of rows, I would use the first approach. The rationale being that each of the three transactions will be smaller than the one combined transaction.

In general it is better to have smaller transactions than one bigger transactions. Of course, I shouldn't generalize - I can already think of one counter example where that is not true.

By the way, and I know you are just showing an example, avoid using select * as much as possible. That can get you (or others) into troubles in the future.
Go to Top of Page
  Previous Topic Topic Next Topic  
 Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.02 seconds. Powered By: Snitz Forums 2000