SQL Server SELECT INTO and Blocking With Temp Tables

后端 未结 8 891
抹茶落季
抹茶落季 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:04

    SELECT INTO #temp_table holds a shema lock in tempdb for the duration of the statement because part of the work it's accomplishing is creating the table. This is fundamentally different than first creating the table using CREATE TABLE #.... and then running a set based INSERT. SELECT INTO does have advantages over INSERT, in particular the operation is minimally logged if the recovery model of the database is simple or bulked log.

提交回复
热议问题