如何从数据库中选择记录并通过原子查询对其进行更新
||
我在带有“状态”列的表中有许多记录,我想选择“状态=待处理”的单个记录,并在同一原子查询中将其标记为“状态=处理中”。最好的方法是什么?
这是必需的,因为可以同时运行多个查询以尝试处理这些记录,并且我不希望两个线程选择相同的记录进行处理。
没有找到相关结果
已邀请:
4 个回复
玖料萄
如果您想获得具有新状态的行或在旧状态下删除该行,则可以在此处使用插入的表名。
公藕
这样的事情应该可以避免死锁。
藐刚
SQL 2008应该为您进行任何锁定。
痴浪墨