Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
[データベースシステム論] 第13回 データベースの運用
--
-- p.36 テーブルのロック - SQL
--
--端末A
START TRANSACTION;
LOCK wine IN ACCESS EXCLUSIVE MODE;
--端末B
SELECT * FROM wine;
--端末A
SELECT * FROM wine;
--ロックが機能していますか??
COMMIT;
--もしくは
ROLLBACK;
--
-- p.38 行のロック- SQL
--
--端末A
START TRANSACTION;
SELECT * FROM wine WHERE wid = 1 FOR UPDATE;
--端末B
START TRANSACTION;
SELECT * FROM wine WHERE wid = 2 FOR UPDATE;
SELECT * FROM wine WHERE wid = 1 FOR UPDATE;
--端末A
UPDATE wine SET price = 100000 WHERE wid = 1;
COMMIT;
--
-- p.40 デッドロック - SQL
--
--端末A
START TRANSACTION;
LOCK wine IN ACCESS EXCLUSIVE MODE;
--端末B
START TRANSACTION;
LOCK vineyard IN ACCESS EXCLUSIVE MODE;
--端末A
LOCK vineyard IN ACCESS EXCLUSIVE MODE;
--端末B
LOCK wine IN ACCESS EXCLUSIVE MODE;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.