English 中文(简体)
增加一个主要关键身份识别栏能解决僵局问题吗?
原标题:Can adding a primary key identity column solve deadlock issues?

我在 SQL 服务器上有一个表格, 并同时用一个存储程序进行 CROUD 同步, 在不同会话中同时运行 :

|----------------|---------|
| <some columns> | JobGUID |
|----------------|---------|

该程序工作如下:

  1. Generate a GUID.
  2. Insert some records into the shared table described above, marking them with the GUID from step 1.
  3. Perform a few updates on all records from step 2.
  4. Select the records from step 3 as SP output.

在存储的程序中,每个选择/插入/更新/更新/删除语句都有一个 WHERE JobGUID = @jobGUID 条款,因此该程序只能使用在步骤2上插入的记录,然而,有时当同一存储程序在不同连接中平行运行时,在共享的表格上出现僵局。下面是 SQL 服务器配置器的僵局图示:

"https://i.sstatic.net/wA5Od.png" alt="SQL服务器配置器死亡图"/ >

锁定升级不会发生。 我尝试在所有 DML 语句中添加 < code> (UPDLOCK, ROWLOCK) 锁定提示, 并(或) 在交易中用不同的孤立级别将程序正文包起来, 但它没有帮助 。 在共享的表格上仍然使用相同的 RID 锁定 。

在我发现共桌没有主钥匙/身份栏之后,我发现共桌没有主要的钥匙/身份栏。 一旦我加进这一栏,僵局似乎就消失了:

alter table <SharedTable> add ID int not null identity(1, 1) primary key clustered

当我去除主键柱时,僵局又回到了过去。 当我把它又加回去时,我不能再重现僵局了。

所以,问题是,一个主要的关键身份识别栏 真的能够解决僵局吗? 还是只是巧合?

最新消息: as < a href="https://stackoverflow.com/uss/562459//catcall" 标题="Catcall"\\Catcall 表示,我尝试在现有栏目上创建自然分组主键(不添加身份栏),但仍然陷入僵局(当然,这次是钥匙锁,而不是RID锁)。

最佳回答

解决僵局的最佳资源(仍然)就在这里:http://blogs.msdn.com/b/bartd/archive/2006/09/09/dealock-troublepling_2c00_-part-1.aspx

Pt #4说:

Run the queries involved in the deadlock through Database Tuning Advisor. Plop the query in a Management Studio query window, change db context to the correct database, right-click the query text and select “Analyze Query in DTA”. Don’t skip this step; more than half of the deadlock issues we see are resolved simply by adding an appropriate index so that one of the queries runs more quickly and with a smaller lock footprint. If DTA recommends indexes (it ll say “Estimated Improvement: %”), create them and monitor to see if the deadlock persists. You can select “Apply Recommendations” from the Action drop-down menu to create the index immediately, or save the CREATE INDEX commands as a script to create them during a maintenance window. Be sure to tune each of the queries separately.

我知道这不会“回答”为什么必然存在的问题, 但是它确实表明,增加指数可以改变执行方式, 使锁定足迹缩小或执行时间加快, 从而大大降低陷入僵局的可能性。

问题回答

最近我看到这个职位, 根据上面的信息 我希望这个职位能帮助你,

http://databaseusergroup.blogspot.com/2013/10-dread late-on-sql-sserver.html>http://databaseusergroup.com/2013/10-dread late-on-sql-server.html http://databaseusergroup.blogspot.com/2013/10/dreedlad-sql-sql-server.html





相关问题
Export tables from SQL Server to be imported to Oracle 10g

I m trying to export some tables from SQL Server 2005 and then create those tables and populate them in Oracle. I have about 10 tables, varying from 4 columns up to 25. I m not using any constraints/...

SQL server: Can NT accounts be mapped to SQL server accounts

In our database we have an SQL server account that has the correct roles to access some of the databases. We are now switching to windows authentication and I was wondering if we can create a NT user ...

SQL Server 2000, ADO 2.8, VB6

How to determine if a Transaction is active i.e. before issuing Begin Transaction I want to ensure that no previous transaction are open.. the platform is VB6, MS-SQL Server 2000 and ADO 2.8

热门标签