表模式(SQL Server 2012)
Create Table InterestBuffer
(
AccountNo CHAR(17) PRIMARY KEY,
CalculatedInterest MONEY,
ProvisionedInterest MONEY,
AccomodatedInterest MONEY,
)
Create Table #tempInterestCalc
(
AccountNo CHAR(17) PRIMARY KEY,
CalculatedInterest MONEY
)
Run Code Online (Sandbox Code Playgroud)
我正在做一个upsert.更新存在的行并插入其他行.
UPDATE A
SET A.CalculatedInterest = A.CalculatedInterest + B.CalculatedInterest
FROM InterestBuffer A
INNER JOIN #tempInterestCalc B ON A.AccountNo = B.AccountNo
INSERT INTO InterestBuffer
SELECT A.AccountNo, A.CalculatedInterest, 0, 0
FROM #tempInterestCalc A
LEFT JOIN InterestBuffer B ON A.AccountNo = B.AccountNo
WHERE B.AccountNo IS NULL
Run Code Online (Sandbox Code Playgroud)
一切都很好.并发执行期间出现问题.我#tempInterestCalc通过加入其他各种表来插入数据,包括与表的左连接,InterestBuffer并#tempInterestCalc为每个并发执行插入不同的数据集.
我的问题是,有时执行会被另一个执行锁定,直到我将它们串行提交. …