From 1c6dc765e773877a432e8650b1abf4e06f980b55 Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 1 Jul 2026 01:18:53 +0300 Subject: [PATCH 1/2] Add transaction for creating an order --- task.sql | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/task.sql b/task.sql index 8adf22b..52f5f0d 100644 --- a/task.sql +++ b/task.sql @@ -1,11 +1,6 @@ --- Use our database -USE ShopDB; - --- Some data should be created outside the transaction (here) - --- Start the transaction +USE ShopDB; START TRANSACTION; - --- And some data should be created inside the transaction - +INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01'); +INSERT INTO OrderItems (ProductID, Count, OrderID) VALUES (1, 1, LAST_INSERT_ID()); +UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; COMMIT; \ No newline at end of file From 31ba4d0ac94b140a0520acd90f2e926982b63376 Mon Sep 17 00:00:00 2001 From: tenshi Date: Wed, 1 Jul 2026 01:26:29 +0300 Subject: [PATCH 2/2] fix: Moved order creation out of the transaction --- task.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/task.sql b/task.sql index 52f5f0d..5e956c6 100644 --- a/task.sql +++ b/task.sql @@ -1,6 +1,6 @@ -USE ShopDB; -START TRANSACTION; +USE ShopDB; INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01'); +START TRANSACTION; INSERT INTO OrderItems (ProductID, Count, OrderID) VALUES (1, 1, LAST_INSERT_ID()); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; COMMIT; \ No newline at end of file