-创建和删除临时表


第一种方式
创建表# TMP(name varchar(255),ID int)

第二方式
select count(ID)为storynum,
和(转换(数字(10,2),在IsNumeric(代码)= 1那么其他代码0))
和((时IsNumeric(瑞科)= 1然后转换(数字(10,2),瑞科)其他0))
tdtname,周期,jiracomponent,jirastatename,价值,storycodellt
从iknow_story_u2000v1r7c00组tdtname,周期,jiracomponent,jirastatename,值为# TMP,storycodellt

-查询临时表
SELECT * FROM # TMP

-删除临时表
如果object_id('tempdb .. # TMP的)不为空
开始
表# TMP
终点




正确删除SQLServer临时表

删除SQLServer临时表和一般表不相同。下面,我们将为您提供其他示例错误和正确的删除操作的参考。我们希望能帮助你。

The temporary table is different from the usual table, and it is saved to the tempDb table.The table name of the temporary table is not the same as the table name you have built, because he wants to create a different temporary table for the same operation of different people.

1、错误删除操作:


-错误的临时表删除操作,因为数据库不同
如果存在(SELECT * FROM sysobjects,object_id = object_id(N'{ DBO }。{ }#诱人)和类型)
开始
删除表{ } { } DBO诱人。
终点
错误的临时表删除操作,因为临时表名已更改
如果存在(SELECT * FROM tempdb.dbo.sysobjects id是object_id(N'{ } #诱人的))
开始
表#诱人
终点


2,正确的删除方法:


-正确的临时表删除
如果object_id('tempdb .. #诱人的)是不空的开始
表#诱人
终点


SQL决定临时表是否存在,临时表是否被删除。




如果object_id('tempdb .. # DL)是无效的
表# DL -删除临时表是否存在
创建表# DL(Neirong char(20),多dlzonjine int,int,int dlshu,dlyin)——重建临时表
插入# DL SELECT * FROM表插入的物理表的数据到临时表