How can I combine multiple tables into one new table? All column headers are the same and in the same order
I have 12 tables in SQL Server with the same columns that I would like to concatenate into one new table. I don't want data / rows to be deleted.
thank
+3
Maggie
source
to share
1 answer
Use union all
:
insert into NewTable(col1, col2)
select col1, col2
from(
select col1, col2 from Table1
union all
select col1, col2 from Table2
union all
select col1, col2 from Table3
.....
)t
You can create a new table by choosing the type:
select col1, col2
into NewTable
from(
select col1, col2 from Table1
union all
select col1, col2 from Table2
union all
select col1, col2 from Table3
.....
)t
+10
Giorgi nakeuri
source
to share