1. 程式人生 > >sql 插入另一個表的查詢結果

sql 插入另一個表的查詢結果


<!--同一個資料庫-->
<!--目標表不存在 -->
select * into 目標表 from 查詢表 where ...
select * into  abc from student 

<!-- 目標表存在  -->   
insert into 目標表 select * from 查詢表 where ...
insert into student select * from abc

<!--跨資料庫-->
<!--目標表不存在 -->
select * into 目標資料庫..目標表 from 查詢資料庫..查詢表 where ....
select * into 資料庫A..student from  資料庫B..student;

<!-- 目標表已經存在-->
insert into 目標資料庫..目標表  select * from 查詢資料庫..查詢表
insert into 資料庫A..aaa select * from 資料庫B..saver;