SQL Server SELECT INTO and Blocking With Temp Tables

后端 未结 8 876
抹茶落季
抹茶落季 2020-12-13 19:08

So, recently a DBA is trying to tell us that we cannot use the syntax of

SELECT X, Y, Z
INTO #MyTable
FROM YourTable

To create temporary ta

8条回答
  •  萌比男神i
    2020-12-13 20:03

    You can get blocking if you create #temp tables inside a transaction. While this is generally not recommended I have seen this done a lot.

    However the blocking this causes is on some system tables in tempdb that do not affect other connections from creating temp tables (except perhaps for SQL versions prior to 2000?). It does mean that running sp_spacesused on tempdb will block unless you set transaction isolation level to read uncommitted. Also viewing properties on tempdb from SSMS will fail and timeout no doubt because it is using read committed transaction isolation level.

提交回复
热议问题