if object_id('Tempdb..#orderby') is not null --Tempdb..#orderby 代表数据库Tempdb中的临时表#orderby
drop table #orderby
select * into #orderby from T_Lines
select * from #orderby
SQL Server创建临时表:
创建临时表
方法一:
create table #临时表名(字段1 约束条件,
字段2 约束条件,
.....)
create table ##临时表名(字段1 约束条件,
字段2 约束条件,
.....)
方法二:
select * into #临时表名 from 你的表;
select * into ##临时表名 from 你的表;
注:以上的#代表局部临时表,##代表全局临时表
查询临时表
select * from #临时表名;
select * from ##临时表名;
删除临时表
drop table #临时表名;
drop table ##临时表名;
本文介绍了在SQLServer中如何创建、查询及删除局部与全局临时表。提供了两种创建临时表的方法:一是直接定义表结构;二是从现有表选择数据创建临时表。并详细解释了如何使用及清理这些临时表。

3万+

被折叠的 条评论
为什么被折叠?



