create table #t(no varchar(20)) --插入 insert into #t(no) select 'a' union all select 'b' union all select 'c' --更新 update #t set no = 'aa' from #t where no = 'a' --删除 delete from #t where no = 'aa'
用完之后drop掉 drop table #t
create table #table(id int)
create table #table(id int) insert into #table(id) values(1) ud update #table set id=12 drop table #table
为什么不使用表变量,表变量的性能比临时表要高的。因为表变量的数据暂时存储在内存中,而不是硬盘上。declare @tmpdata table (categoryid int,categorynm varchar(50))  insert into @tmpdata (categoryid, categorynm) select categoryid, categoryname from categories  select * from @tmpdata
--插入
insert into #t(no)
select 'a'
union all select 'b'
union all select 'c'
--更新
update #t
set no = 'aa'
from #t
where no = 'a'
--删除
delete from #t where no = 'aa'
drop table #t
insert into #table(id) values(1)
ud
update #table set id=12
drop table #table

insert into @tmpdata (categoryid, categorynm)
select categoryid, categoryname from categories

select * from @tmpdata