在 T-SQL 中,如何做到这一点:
DECLARE @amount decimal(18,2) = 1000
UPDATE account
SET balance = balance + @amount WHERE accountID= 1;
UPDATE account
SET balance = balance - @amount WHERE accountID= 2;
在一个更新查询中以确保例如。没有人在两次更新之间更改帐户货币?当 ID = 1 的行被锁定时,我希望 ID = 2 的行也被锁定。隔离级别被读取提交。就像是:
DECLARE @amount decimal(18,2) = 1000
UPDATE account
SET balance = balance + @amount WHERE accountID= 1;
AND
SET balance = balance - @amount WHERE accountID= 2;
是乘法运算符,这
*
意味着amount * -1 = - amount
- dat-nguyen