求一SQL语句,将一张表的数据导入另一张表
现有表Table1、Table2,结构如下,求一SQL语句,将Table1的所有数据存储到Table2中,谢谢~
Table1
col1 col2 col3 col4 col5
1 2 3 4 5
6 7 8 9 10
11 12 13 14 15
16 17 18 19 20
.....
1001 1002 1003 1004 1005
table2
newCol
1
2
3
4
5
6
....
1005
------解决方案--------------------insert into Table2(newCol) select col1 from Table1
union all select col2 from Table1
union all select col3 from Table1
union all select col4 from Table1
union all select col5 from Table1
------解决方案--------------------insert table2
select col1 from tabel1 union all
select col2 from tabel1 union all
select col3 from tabel1 union all
select col4 from tabel1 union all
select col5 from tabel1
------解决方案--------------------弄成一列?
insert into tb2 (select col1 from tb2 union all select col2 from tb2 union all select col3 from tb2 union all select col4 from tb2 union all select col5 from tb2)
------解决方案--------------------以上的这些语句只能把结果都显示出来,但不能排序啊,有没有一条语句可以直接排序的啊?
------解决方案--------------------create table tb(col1 int , col2 int , col3 int , col4 int , col5 int)
insert into tb values(1,2,3,4,5)
insert into tb values(6,7,8,9,10)
insert into tb values(11,12,13,14,15)
insert into tb values(16,17,18,19,20)
go
select * from
(
select col1 from tb union all
select col2 from tb union all
select col3 from tb union all
select col4 from tb union all
select col5 from tb
) t order by col1
drop table tb
/*
col1
-----------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
(所影响的行数为 20 行)
*/
------解决方案--------------------SELECT * INTO TABLE2 FROM TABLE1
------解决方案--------------------insert into 55
select col1 from tb union ..... order by col1