我在PK数据库中存了很多结构相同的表,现在想把它们合并,并且写到另一个数据库analysis中的zb中,并加一个ID字段,请问该如何处理?
解决方案 »
- Navicat 8.0 MySQL 为什么连接不起 急!!!
- 这么多的表,如何把记录组合起来
- 请教这样一个sql语句~~
- 求一个统计,涉及3个表,要生成一个结果集
- Windows2008 安装SqlServer2008提示错误,无法继续安装
- 数据表之间的连接问题(----------------在线等-----------------)
- 请教过滤UBB代码的sql语句
- happydreamer(黑DD) ,pengdali(大力) ( ) 請進
- 如何利用存储过程产生交叉表问题!由于是web页上要用!在asp.net里问了多次没有结果!到这来碰碰运气了
- 为什么SQL的自动定期备份,都不起作用?
- sql语句运行时异常
- 求解!!java 连接 sqlserver2005 jdbc 问题!在线等待!
select id = identity(int,1,1),*
into B..newtable
from (
select a1,a2,a3 from A..t1
union all
select a1,a2,a3 from A..t2
union all
select a1,a2,a3 from A..t3
)t
into analysis.newtable
from (
select * from PKCorpusFrequence.C20001104
union all
select * from PKCorpusFrequence.C20001105
union all
select * from PKCorpusFrequence.C20001106
)t
为什么会显示对象名 'PKCorpusFrequence.C20001104' 无效。
into analysis..newtable
from (
select * from PKCorpusFrequence..C20001104
union all
select * from PKCorpusFrequence..C20001105
union all
select * from PKCorpusFrequence..C20001106
)t
if object_id('tb1') is not null drop table tb1
GO
create table tb1(id int identity,val int)
insert into tb1
select 1 union all
select 2
select * from tb1if object_id('tb2') is not null drop table tb2
GO
create table tb2(id int identity,val int)
insert into tb2
select 21 union all
select 22 select * from tb2if object_id('tb3') is not null drop table tb3
GO
create table tb3(id int identity,val int)
insert into tb3
select 331 union all
select 332 select * from tb3--将tb1 tb2数据插入tb3中
insert into tb3(val)
select val from tb1 union all
select val from tb2select * from tb3
/* 结果(2 行受影响)
id val
----------- -----------
1 1
2 2(2 行受影响)
(2 行受影响)
id val
----------- -----------
1 21
2 22(2 行受影响)
(2 行受影响)
id val
----------- -----------
1 331
2 332(2 行受影响)(4 行受影响)id val
----------- -----------
1 331
2 332
3 1
4 2
5 21
6 22(6 行受影响)
*/