What's blocking “Select top 1 * from TableName with (nolock)” from returning a result?

前端 未结 4 1915
余生分开走
余生分开走 2021-02-20 14:37

I\'m currently running the following statement

select * into adhoc..san_savedi from dps_san..savedi_record

It\'s taking a painfully long time a

4条回答
  •  庸人自扰
    2021-02-20 14:52

    A few issues to consider here. Is dps_san..savedi_record a view? If so, it could just be taking a really long time to get your data. The other thing I can think of is that you're trying to create a temp table by using the select into syntax, which is a bad idea. select * into ... syntax will lock the tempdb for duration of the select.

    If you are creating the table using that syntax, then there is a workaround. First, create the table by throwing where 1=0 at the end of your initial statement:

    select * into ... from ... where 1=0
    

    This will create the table first (which is quick) which allows you to insert into because the table exists now (without penalty of locking tempdb for duration of query).

提交回复
热议问题