sql - 删除临时表(如果 SQL Azure 上存在)

标签 sql sql-server azure temp-tables

是否有更好的方法在 Azure SQL 上删除临时表?

BEGIN TRY
    DROP TABLE #customMap
END TRY
BEGIN CATCH
END CATCH

也许不需要删除 Azure SQL 上的临时表,因为 session 结束时表会被删除。

这个

if (OBJECT_ID('#candidates')) is not null
begin
    drop table #candidates;
end;

或者这个

if (OBJECT_ID('tempdb..#candidates')) is not null
begin
    drop table #candidates;
end;

不起作用。

最佳答案

在 Azure SQL 数据库中,您可以使用 DROP IF EXISTS (DIE) 语法:

create table #temp (id int)

drop table if exists #temp

关于sql - 删除临时表(如果 SQL Azure 上存在),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30531728/

相关文章:

sql - 如何在sql server中创建带有字符和数字(如字母数字)的自动增量列?

sql - SSIS - 将 nchar 空字符串转换为 int 时出现表达式计算错误

azure - 更改 Application Insights 的位置?

Azure - 获取已删除的用户 - 使用 Get-AzureADUser

azure - GitHub 组织未出现在“持续部署”页面中

mysql - 将最大值设置为默认值

mysql - AVG(TIMESTAMPDIFF) mySQL 返回错误答案

SQL如何更新同一个表中组的列的SUM

c# - sql存储过程与代码,对于大量数据,哪个更好?

sql-server - 如何将值传递给OLE DB Source组件中的存储过程参数?