IF EXISTS 不会降低温度 table
IF EXISTS does not drop the temp table
这可能是一个多部分问题:
当我发表声明时
IF OBJECT_ID('temp..#tablename) IS NOT NULL --drop the table here
它不会降低温度 table。当我查看临时数据库时,名称完全不同...
#tablename___________________________________________00000001069F
显然,drop 语句不适用于此。我怎样才能确保 temp table 被上面的语句删除。
此外,如果我在 create temp table 语句之前使用 "USE dbName",temp table 是否仍会在 tempdb 或 dbName 数据库中创建?默认值总是 tempDb 吗?
谢谢,
房车
使用应该使用
OBJECT_ID('tempDB..#tablename')
没有
OBJECT_ID('temp..#tablename')
does the temp table still get created in tempdb or the the dbName database? Is the default always tempDb?
是
临时表总是在 TEMPDB 中创建..
您看到 _____00000001069F
这样的名称的原因是临时表是特定于会话的,SQL 负责为它们分配名称,这样名称就不会冲突,即使它们在同名的并行会话中使用
在 DBA.SE 上查看此答案以获取更多信息,具体请查看临时表部分:
What's the difference between a temp table and table variable in SQL Server?
这可能是一个多部分问题:
当我发表声明时
IF OBJECT_ID('temp..#tablename) IS NOT NULL --drop the table here
它不会降低温度 table。当我查看临时数据库时,名称完全不同...
#tablename___________________________________________00000001069F
显然,drop 语句不适用于此。我怎样才能确保 temp table 被上面的语句删除。
此外,如果我在 create temp table 语句之前使用 "USE dbName",temp table 是否仍会在 tempdb 或 dbName 数据库中创建?默认值总是 tempDb 吗?
谢谢, 房车
使用应该使用
OBJECT_ID('tempDB..#tablename')
没有
OBJECT_ID('temp..#tablename')
does the temp table still get created in tempdb or the the dbName database? Is the default always tempDb?
是
临时表总是在 TEMPDB 中创建..
您看到 _____00000001069F
这样的名称的原因是临时表是特定于会话的,SQL 负责为它们分配名称,这样名称就不会冲突,即使它们在同名的并行会话中使用
在 DBA.SE 上查看此答案以获取更多信息,具体请查看临时表部分:
What's the difference between a temp table and table variable in SQL Server?