首页 > 数据库技术 > 详细

sql插入临时表数据的方法

时间:2017-02-22 13:29:43      阅读:305      评论:0      收藏:0      [点我收藏+]

方法有两种,主要看需求。

方法1:定义好临时表的字段和类型、插入对应的值

create table #Tmp --创建临时表#Tmp
(
    City   varchar(50),  --
    Country  varchar(50),   --
);

insert #Tmp
select 北京,中国 union
select 东京,日本 union
select 纽约,美国 

select * from #Tmp;

技术分享

 

方法2:直接将查询出来的表数据插入临时表中

if OBJECT_ID(tempdb..#temp) is not null
drop table #temp
select * into #temp from 
(
    --select * from Activity
    select 7 as month,25 as day
    union all
    select 7 as month,25 as day
    union all
    select 8 as month,25 as day 
    union all
    select 8 as month,25 as day
    union all
    select 8 as month,25 as day
 
) as A


select *  from #temp

技术分享

 

 欢迎顶....

sql插入临时表数据的方法

原文:http://www.cnblogs.com/hmYao/p/6428256.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!