我在PK数据库中存了很多结构相同的表,现在想把它们合并,并且写到另一个数据库analysis中的zb中,并加一个ID字段,请问该如何处理?
解决方案 »
- 存储过程
- sql语句中如何去掉字段的空格?
- 求助行列转换,谢谢
- 存储过程里如何调用存储过程
- 请问一下 sql server 2000中如何将大量文本写入数据库
- SQL2005 INFORMATION_SCHEMA.PARAMETERS视图中当存储过程参数为NVARCHAR(MAX)时CHARACTER_MAXIMUM_LENGTH为-1
- 为什么sql2005的生成的追踪trc不能用read80trace导入数据库呀
- 空记录问题
- 关于MSSQL的触发器的问题.
- 有用过SQL Server扩展存储过程的吗?
- 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 行受影响)
*/