SQL Server SELECT INTO and Blocking With Temp Tables

后端 未结 8 879
抹茶落季
抹茶落季 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条回答
  •  眼角桃花
    2020-12-13 19:58

    Why not do the following?

    SELECT X, Y, Z
    INTO #MyTable
    FROM YourTable
    WHERE 1 = 2
    

    The statement would run instantly - creating your temp table and avoiding any possible locking. Then you could insert into it as usual:

    INSERT #MyTable
    SELECT X, Y, Z
    FROM YourTable
    

提交回复
热议问题