我目前正在将数据库从MSSQL更改为MYSQL,并且遇到一个包含OUTPUT INSERTED的查询的问题。*
我尝试为MYSQL进行尽可能准确的转换,但是查询出现死锁错误。
任何人都可以告诉我我要去哪里哪里或应该如何处理这种情况。
MSSQL查询:
UPDATE TestSessionScenarios
SET AssignedAt = GETUTCDATE()
OUTPUT INSERTED.*
WHERE Id = (SELECT TOP 1 t1.Id
FROM TestSessionScenarios t1 WITH (UPDLOCK, HOLDLOCK)
WHERE t1.TestSessionId = {0}
AND t1.AssignedAt IS NULL
ORDER BY t1.FailureCount ASC)
MYSQL转换:
START TRANSACTION;
SET SESSION TRANSACTION ISOLATION LEVEL READ UNCOMMITTED ;
UPDATE TestSessionScenarios
SET AssignedAt = NOW(), Id = LAST_INSERT_ID(Id)
WHERE Id = (SELECT * FROM (
SELECT t1.Id
FROM TestSessionScenarios t1
WHERE t1.TestSessionId = {0}
AND t1.AssignedAt IS NULL
ORDER BY t1.FailureCount ASC
LIMIT 1) as temp);
SELECT * from TestSessionScenarios WHERE Id = LAST_INSERT_ID();
COMMIT;
预先感谢您:)