我有一个表“Alert_List”,上面正在运行两个会话。
第1节:
insert into Alert_List values ( "required values")
第2节:
Update A
set Active = 0
from Alert_List A
left join STG_Alert B on A.Alert_List_Id = B.Alert_List_Id
left join STG_UserID C on A.UserID = C.UserID
where B.Alert_List_Id is null and C.UserID is null
此处STG_Alert,STG_UserID
是临时表,其中包含一些不需要停用的Alert_List_Id
和UserID
。
Alert_List上的索引如下。
ALTER TABLE [dbo].[Alert_List] ADD CONSTRAINT [PK_EA_List] PRIMARY KEY CLUSTERED
(
[Alert_List_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, IGNORE_DUP_KEY = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
CREATE NONCLUSTERED INDEX [Alert_List_INDEX] ON [dbo].[Alert_List]
(
[AVE_Id] ASC,
[Request_Id] ASC,
[User_Id] ASC,
Active ASC,
[Process_Id] ASC,
[Status_Id] ASC
)
INCLUDE ( [Alert_List_Id]) WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
CREATE NONCLUSTERED INDEX [indexeaml] ON [dbo].[Alert_List]
(
[User_Id] ASC,
[Process_Id] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, SORT_IN_TEMPDB = OFF, DROP_EXISTING = OFF, ONLINE = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON)
GO
上述两个查询失败,但发生以下错误。
事务(进程ID 85)在锁资源上与另一个进程发生死锁,并被选为死锁牺牲品。重新运行该交易。
在这种情况下,我不想使用WITH(NOLOCK)
或ALLOW_SNAPSHOT_ISOLATION
。
如果您有任何其他方法可以解决此问题,请与我们联系。