I think you should work take into considerations two factors:
- Hardware and server specifications
- Data size
If the machine specifications you are working with are not very performant and you have a huge size of data, then distributing the INSERT
operation (multiple INSERT) will enhance the performance because it will not consume the memory like a UNION
operation.
If the data size is acceptable and can be handled by SQL Server allocated memory, then you should use common table expression with a SELECT INTO
query:
WITH CTE_1 as (SELECT * FROM TABLE_1
UNION ALL
SELECT * FROM TABLE_2
UNION ALL
SELECT * FROM TABLE_3)
SELECT *
INTo New_Table
FROM CTE_1
Also note the difference between UNION
and UNION ALL
operations:
A UNION statement effectively does a SELECT DISTINCT on the results set. If you know that all the records returned are unique from your union, use UNION ALL instead, it gives faster results. Also try to avoid INSERT INTO
and use SELECT INTO
instead because it is minimally logged assuming proper trace flags are set.
Another thing to mention, (i didn't tested this approach but maybe it should gives better performance - and it may caused a huge index size) you should also try to create an indexed view over all tables (UNION query you have mentioned), then execute the query, as example:
SELECT * INTO ... FROM vw_Unified
Update 1
If you are familiar with SSIS, performing data import process may gives better performance when using SSIS: