检查是否存在临时表并删除表 [英] Check if a temporary table exists and drop the table

查看:142
本文介绍了检查是否存在临时表并删除表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



我要检查是否有临时表并删除它是否存在。我使用了这句话:

   DROP TABLE IF EXISTS ptempTable 

但访问引发错误说drop table或drop index.Drop table语句中的语法错误工作正常,但为什么在检查现有表时它不起作用?

有没有办法解决它?

解决方案

喜欢这个?



  IF   OBJECT_ID '  tempdb ..#Temp' IS   NOT   NULL  < span class =code-keyword> DROP   TABLE  #Temp 

创建 #Temp(ID INT ,名称 NVARCHAR 100 ))


Hi all,

I was going to check if a temporary table and delete if it exists.And i used this statement:

"DROP TABLE IF EXISTS ptempTable"

But access is raising an error saying Syntax error in drop table or drop index.Drop table statement works fine but why doesn't it work when checking for existing table?
Is there a way to solve it?

解决方案

Like this?

IF OBJECT_ID('tempdb..#Temp') IS NOT NULL DROP TABLE #Temp

CREATE TABLE #Temp (ID INT, Name NVARCHAR(100))


这篇关于检查是否存在临时表并删除表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆