sql server 单表死锁问题
我在 sql server 2000 中有一张表,比方说“xxx”。一个 .exe 正在通过 sql 作业将数据插入到该表“xxx”中。但是,一旦插入数据,一个存储过程就会从该“xxx 表”中读取数据,然后插入/更新到其他两个表中,并将状态更新回同一个“xxx”表中。现在,客户说该“xxx”表上发生了多个死锁。请任何人告诉我解决此死锁问题所需采取的解决步骤以及如何逐步识别它......
提前感谢...... XXX
I have one table let's say "xxx "in sql server 2000 . One .exe is inserting data into that table "xxx" through sql job. But once data is inserted , one stored procedure is reading the data from that "xxx table "and inserting/updating into other two tables and updating back the status into the same "xxx" table. Now, client says that multiple deadlocks are occuring on that "xxx" table . please kindly anyone sdvice me the resolution steps to be taken to resolve this deadlock issue and how to identify it step by step.............
Thanks in advance.....
XXX
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
即使我可以访问您的系统和所有代码,这也是一个非常难以解决的问题。也就是说,您在问题中没有提供很多细节。
因此,应用减少 SQL Server 死锁的一般规则:
Even if I had access to your system and all of your code, this is a very difficult issue to resolve. That said, you don't provide many details in your question.
So apply the general rules of Reducing SQL Server Deadlocks:
您可以尝试对读取行的查询应用提示:with(updlock,holdlock)。如果您没有聚集索引,请尝试创建一个在选择阶段使用的聚集索引。如果可能的话,尝试减少事务中处理的行数。
是否可以先更新表中的行,然后填充其他表?如果出现错误,您可以回滚事务。
我不建议使用 NOLOCK 提示,尤其是当您更新相同的数据时。
You might try to apply hint to the query that reads the rows: with(updlock, holdlock). Try to create a clustered index that would be used during the select phase if you don't have one. Try to narrow the amount of rows processed in transactions, if possible.
Is it possible to first update rows in the table and then populate other tables? If there is an error you can roll back the transaction.
I don't recommend using NOLOCK hint especially when you are updating the same data.
根据我使用 Sql Server 2000 的经验,避免死锁的最佳方法是限制查询内的并行性。
这可以通过添加两个查询(插入和 SP)或什至只是在查询末尾插入提示选项(Maxdop 1)来完成。
这会限制性能,但您可以安全执行。
如果只有一个线程正在运行,则没有其他线程可能发生死锁。
From my experience with Sql Server 2000 best way to avid deadlocks is to limit parallelism inside the query.
This can be done by adding on both queries (insert and SP) or even just the insert the hint Option (Maxdop 1) at the end of the query
This will limit the performance but you have a safe execution.
If only one thread is running there is no other thread that can deadlock.