首页 > 解决方案 > 触发后如何删除lockTable?

问题描述

我有一个触发器:

Create trigger Update_applicationUpdate_MainTable 
on MainTable 
after update 
as
    Update [SubTable] with(ROWLOCK) 
    set [LatUpdateTime] = SYSDATETIME() 
    where [dbo].[SubTable].[ClientTableId] in (select Id from inserted) 
      and [Table] = '[dbo].[MainTable]';

交易开始后:

update [dbo].[MainTable]
set [Name] = 'Test1' 
where id = 1

锁定MainTableandSubTable进行另一笔交易。

如何只阻止一行?

我的第二个事务,但它挂起,因为触发器正在锁定表:

update [dbo].[MainTable]
set [Name] = 'Test1' 
where id = 2

我只使用 SQL Server

标签: sqlsql-server

解决方案


推荐阅读