下面的代码可以工作并且非常精确,但是与其他“标准”方法相比,这样做是否可以?
--Drop table if exists
begin try
drop table #temp
end try
begin catch
print 'table does not exist'
end catch
--Create table
create table #temp(a int, b int)
最佳答案
最好用
If Object_Id('Tempdb..#temp') Is Not Null
Drop Table #temp
create table #temp
因为你打算最终创建一个#temp Table,它不需要try catch来给出#temp Table不存在的错误消息
如果 create 语句在 try 中,它可能会有一些用处
关于sql - 使用 try-catch block 在 Sql-Server 中删除表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42622818/