Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Luuk123
Yak Posting Veteran
52 Posts |
Posted - 2014-02-21 : 04:01:39
|
Hi all,I have a query which inserts data from different sources into one table. Now it's like this:Insert into tabselect *from source_tab_aInsert into tabselect *from source_tab_bInsert into tabselect *from source_tab_cI'm wondering which is better, the above separate insert query's or the following:insert into tabselect * from source_tab_aunion allselect * from source_tab_bunion allselect * from source_tab_cCan somebody explain?Thanks! |
|
James K
Master Smack Fu Yak Hacker
3873 Posts |
Posted - 2014-02-21 : 15:17:21
|
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. |
|
|
|
|
|