如何删除 Sql Server 2005 中存在的临时 SP [英] How To Drop Temporary SP If Exists in Sql Server 2005
本文介绍了如何删除 Sql Server 2005 中存在的临时 SP的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的问题很简单!如果存在临时存储过程,如何删除?这是因为当我在脚本中创建一个临时 SP 时,它会在我第二次运行时抛出错误,例如数据库中已经有一个名为‘#sp_name’的对象".我不想向用户显示此消息.请帮我.您的解决方案非常受欢迎!
My Question is simple! How to Drop a Temporary Stored Procedure If Exists ? This is because while I create a Temporary SP in a script, it throws error like 'There is already an object named '#sp_name' in the database' while i run the Second time. I dont want to show this message to users. Please help me. Your solution is Highly appereciated!
推荐答案
临时 proc 的删除方式与永久 proc 的删除方式相同.请看下面的代码:
The temp procs are dropped in the same way as permanent procs are dropped. Please see the code below:
-- Create test temp. proc
CREATE PROC #tempMyProc as
Begin
print 'Temp proc'
END
GO
-- Drop the above proc
IF OBJECT_ID('tempdb..#tempMyProc') IS NOT NULL
BEGIN
DROP PROC #tempMyProc
END
这篇关于如何删除 Sql Server 2005 中存在的临时 SP的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文