求一SQL语句,将一张表的数据导入另一张表

sunfly028 2007-08-20 11:13:56
现有表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
...全文
432 9 打赏 收藏 转发到动态 举报
写回复
用AI写文章
9 条回复
切换为时间正序
请发表友善的回复…
发表回复
rfq 2007-08-21
  • 打赏
  • 举报
回复
insert into 55
select col1 from tb union ..... order by col1
buxiangwei 2007-08-21
  • 打赏
  • 举报
回复
SELECT * INTO TABLE2 FROM TABLE1
dawugui 2007-08-20
  • 打赏
  • 举报
回复
弄成一列?

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)
dawugui 2007-08-20
  • 打赏
  • 举报
回复
现有表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

insert into tb2 select * from tb1
mengmou 2007-08-20
  • 打赏
  • 举报
回复
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
子陌红尘 2007-08-20
  • 打赏
  • 举报
回复
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
dawugui 2007-08-20
  • 打赏
  • 举报
回复
insert into tb1
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
dawugui 2007-08-20
  • 打赏
  • 举报
回复
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 行)
*/

chenjg85 2007-08-20
  • 打赏
  • 举报
回复
以上的这些语句只能把结果都显示出来,但不能排序啊,有没有一条语句可以直接排序的啊?

34,590

社区成员

发帖
与我相关
我的任务
社区描述
MS-SQL Server相关内容讨论专区
社区管理员
  • 基础类社区
  • 二月十六
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧