开发者

Best way to perform a SELECT statement and insert into the same table?

Does anybody have any suggestions on how to improve the following statements:

insert into ProductInfo with (rowlock) (orderid, productname)
      select 66673, FileInfoId
        from ProductInfo with (nolock) where 
          Prod开发者_如何学CuctId = 66671 and
          IsEligableForCopy = 1 and 
          ProductFileInfoId >= 2768395941 and 
          ProductFileInfoId < 2768405941


It sounds like it is timing out because it fails to obtain a lock. What DBMS are you using? And have you tried it without requesting a lock? The example you present appears to be a one-time insert, but I assume this is just an example, as opposed to something you would run in production.


Improve or add indicies on ProductInfo...maybe it won't timeout


The Query looks fine. It should be running perfectly. Is there anything specific that you want to achieve.?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜