我怎么知道哪个事务先运行

时间:2019-11-01 06:08:01

标签: mysql database transactions isolation-level transaction-isolation


SET TRANSACTION ISOLATION LEVEL SERIALIZABLE

INSERT INTO Students VALUES(’Jason’,50);

UPDATE Students SET mark = mark + 10;

COMMIT

SET TRANSACTION ISOLATION READ COMMITED

INSERT INTO Students VALUES (’Kylie’,70);

SELECT SUM(mark) FROM Students;

COMMIT

如果我有两个同时运行的事务,我怎么知道先运行什么以及查询将返回什么值?我知道Serializable可以隔离T1。但除此之外,我不知道如何进行。

1 个答案:

答案 0 :(得分:0)

如果您同时运行两个命令,则READ COMMITTED将等待SERIALIZABLE完成。顺便说一句,您的BEGIN TRANSACTION似乎缺少TSQL

SET TRANSACTION ISOLATION LEVEL SERIALIZABLE
BEGIN TRANSACTION
   INSERT INTO Students VALUES(’Jason’,50);
   UPDATE Students SET mark = mark + 10;
COMMIT TRANSACTION

SET TRANSACTION ISOLATION READ COMMITTED
BEGIN TRANSACTION
   INSERT INTO Students VALUES (’Kylie’,70);
   SELECT SUM(mark) FROM Students;
COMMIT TRANSACTION