Insert Statement into same table 导致不一致的瓶颈
Insert Statement into same table causes inconsistent bottlenecking
我目前在数据库中使用的特定 SQL 服务器 table 有问题,当我选择的记录来自它自己。
声明如下:
insert into [Custom Work] ([Description], [Price], [Cost], [Labour Cost], [Made In Material], [Bought Out Material], [Weight], [Machine Shop], [Axles], [Stakes/Bunks], [Beam], [GNK], [Parts], [Line], [Step 1], [Step 2], [Blast], [Paint], [Finish], [Finish - GNK], [Final Assembly], [Shipping], [Eng Hours], [Option Date])
select
[Description], [Price], [Cost], [Labour Cost],
[Made In Material], [Bought Out Material], [Weight],
[Machine Shop], [Axles], [Stakes/Bunks], [Beam],
[GNK], [Parts], [Line], [Step 1], [Step 2],
[Blast], [Paint], [Finish], [Finish - GNK],
[Final Assembly], [Shipping], [Eng Hours], [Option Date]
from
[Custom Work]
where
Description = 'custom stuff'
and Quote# = 123456
当我从另一个 table 插入记录时(比如当我们添加一个标准选项作为自定义工作时),它像往常一样工作得很好!但是当我从它自己插入记录时,它会在这里和那里工作但然后超时(当 运行 从 Access 时)或永远继续(如果 运行 从 SSMS)。
这在我进行了一些 table 结构更改后开始发生,但是我对标准选项进行了相同的结构更改 table 我们有...所以,如果我无法插入记录我不应该能够从另一个 table 插入记录! :|
我还 运行 跟踪以帮助诊断此问题,但它并不能提供太多线索...
没有设置针对此 table 的触发器,select/update 语句也可以正常工作(根据我所做的所有实验)!我什至在几个小时后重新启动了 SQL Server (运行ning SQL Server 2008 R2)(这通常为我解决了这个问题),但这次没有。
我猜可能损坏了 table 属性(foreign/primary 键、约束、索引、统计信息等)?任何帮助将不胜感激:)
编辑: 仅在此 table 上删除并创建语句是否可以解决此问题?如果不是,请删除并重新创建所有 table 属性?
您尝试过使用 WITH (NOLOCK) 吗?
insert into [Custom Work] ([Description], [Price], [Cost], [Labour Cost], [Made In Material], [Bought Out Material], [Weight], [Machine Shop], [Axles], [Stakes/Bunks], [Beam], [GNK], [Parts], [Line], [Step 1], [Step 2], [Blast], [Paint], [Finish], [Finish - GNK], [Final Assembly], [Shipping], [Eng Hours], [Option Date])
select
[Description], [Price], [Cost], [Labour Cost],
[Made In Material], [Bought Out Material], [Weight],
[Machine Shop], [Axles], [Stakes/Bunks], [Beam],
[GNK], [Parts], [Line], [Step 1], [Step 2],
[Blast], [Paint], [Finish], [Finish - GNK],
[Final Assembly], [Shipping], [Eng Hours], [Option Date]
from
[Custom Work] WITH (NOLOCK)
where
Description = 'custom stuff'
and Quote# = 123456
通过与 Yugz 聊天讨论这个问题后,这个问题一直存在于这个特定的 table 因为我的前端 Access 数据库仍然锁定了这个 table 上的记录(这导致我的无锁插入旋转和阻碍 SQL 性能的语句)。另外,我没有定期重建我的 SQL 数据库索引。
因此,对于遇到此问题的任何其他人,请确保选择数据的前端应用程序未锁定记录并重建索引! :)
我目前在数据库中使用的特定 SQL 服务器 table 有问题,当我选择的记录来自它自己。
声明如下:
insert into [Custom Work] ([Description], [Price], [Cost], [Labour Cost], [Made In Material], [Bought Out Material], [Weight], [Machine Shop], [Axles], [Stakes/Bunks], [Beam], [GNK], [Parts], [Line], [Step 1], [Step 2], [Blast], [Paint], [Finish], [Finish - GNK], [Final Assembly], [Shipping], [Eng Hours], [Option Date])
select
[Description], [Price], [Cost], [Labour Cost],
[Made In Material], [Bought Out Material], [Weight],
[Machine Shop], [Axles], [Stakes/Bunks], [Beam],
[GNK], [Parts], [Line], [Step 1], [Step 2],
[Blast], [Paint], [Finish], [Finish - GNK],
[Final Assembly], [Shipping], [Eng Hours], [Option Date]
from
[Custom Work]
where
Description = 'custom stuff'
and Quote# = 123456
当我从另一个 table 插入记录时(比如当我们添加一个标准选项作为自定义工作时),它像往常一样工作得很好!但是当我从它自己插入记录时,它会在这里和那里工作但然后超时(当 运行 从 Access 时)或永远继续(如果 运行 从 SSMS)。
这在我进行了一些 table 结构更改后开始发生,但是我对标准选项进行了相同的结构更改 table 我们有...所以,如果我无法插入记录我不应该能够从另一个 table 插入记录! :|
我还 运行 跟踪以帮助诊断此问题,但它并不能提供太多线索...
没有设置针对此 table 的触发器,select/update 语句也可以正常工作(根据我所做的所有实验)!我什至在几个小时后重新启动了 SQL Server (运行ning SQL Server 2008 R2)(这通常为我解决了这个问题),但这次没有。
我猜可能损坏了 table 属性(foreign/primary 键、约束、索引、统计信息等)?任何帮助将不胜感激:)
编辑: 仅在此 table 上删除并创建语句是否可以解决此问题?如果不是,请删除并重新创建所有 table 属性?
您尝试过使用 WITH (NOLOCK) 吗?
insert into [Custom Work] ([Description], [Price], [Cost], [Labour Cost], [Made In Material], [Bought Out Material], [Weight], [Machine Shop], [Axles], [Stakes/Bunks], [Beam], [GNK], [Parts], [Line], [Step 1], [Step 2], [Blast], [Paint], [Finish], [Finish - GNK], [Final Assembly], [Shipping], [Eng Hours], [Option Date])
select
[Description], [Price], [Cost], [Labour Cost],
[Made In Material], [Bought Out Material], [Weight],
[Machine Shop], [Axles], [Stakes/Bunks], [Beam],
[GNK], [Parts], [Line], [Step 1], [Step 2],
[Blast], [Paint], [Finish], [Finish - GNK],
[Final Assembly], [Shipping], [Eng Hours], [Option Date]
from
[Custom Work] WITH (NOLOCK)
where
Description = 'custom stuff'
and Quote# = 123456
通过与 Yugz 聊天讨论这个问题后,这个问题一直存在于这个特定的 table 因为我的前端 Access 数据库仍然锁定了这个 table 上的记录(这导致我的无锁插入旋转和阻碍 SQL 性能的语句)。另外,我没有定期重建我的 SQL 数据库索引。
因此,对于遇到此问题的任何其他人,请确保选择数据的前端应用程序未锁定记录并重建索引! :)