1. 程式人生 > >SQL:將查詢結果插入到另一個表的三種情況

SQL:將查詢結果插入到另一個表的三種情況

一:如果要插入目標表不存在:

select * into 目標表 from 表 where ...

二:如果要插入目標表已經存在:

insert into 目的表 select * from 表 where 條件

三:如果是跨資料庫操作的話: 怎麼把A資料庫的atable表所查詢的東西,全部插入到B 資料庫的btable表中

select * into B.btable from A.atable where ...

同樣,如果是跨伺服器的,也是可以的。