T-SQL 一张表如何在查询的时候将结果插入到另一个数据库的表中,就是跨数据库的表操作

如题所述

语句形式为:insert into 数据库名.框架名.表名(列名) select (列名) from 数据库名.框架名.表名 where 条件

类似这样写就行了

insert into MyEmp.dbo.tjdjb(yybh)
select yybh
from MyCmd.dbo.tjdjb where djrq='2009-10-15' and yybh = '11'
select a,c INTO Table2 from Table1追问

用Select into怎么写

追答

select 字段A,字段B,字段C INTO 新表 from 被复制的表 where 条件 ,其中ABC字段为被复制表中的字段,
create table a
( a int,
b int,
c int)
go
insert into a values(1,1,1)
insert into a values(2,3,1)
insert into a values(4,5,8)
insert into a values(2,6,1)
将a表中字段a=2的记录找出插入到新表b中
select a,b,c into b from a where a=2

温馨提示:答案为网友推荐,仅供参考
第1个回答  2011-10-20
select * from table1 insert into table2;
大概就是这样,具体你再搜索下insert into追问

是跨数据库的,两张表不在同一个数据库

追答

是什么数据库?用导出导入就很方便了。
或者select * from dba.table1 insert into dbb.table2;
试试