检查临时表是否存在
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了检查临时表是否存在相关的知识,希望对你有一定的参考价值。
Verify whether temporary table created is exists or not
--Create table USE Norhtwind GO CREATE TABLE #temp(id INT) --Check if it exists IF OBJECT_ID('tempdb..#temp') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Another way to check with an undocumented optional second parameter IF OBJECT_ID('tempdb..#temp','u') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --Don't do this because this checks the local DB and will return does not exist IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END --unless you do something like this USE tempdb GO --Now it exists again IF OBJECT_ID('tempdb..#temp','local') IS NOT NULL BEGIN PRINT '#temp exists!' END ELSE BEGIN PRINT '#temp does not exist!' END
以上是关于检查临时表是否存在的主要内容,如果未能解决你的问题,请参考以下文章