From 6b57406e2f57dffea83112e0d2afceef517e4fb6 Mon Sep 17 00:00:00 2001 From: Alexandr Titarenko Date: Tue, 26 May 2026 13:04:46 +0300 Subject: [PATCH 1/5] Solution --- task.sql | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 8adf22b..6df9757 100644 --- a/task.sql +++ b/task.sql @@ -2,10 +2,15 @@ USE ShopDB; -- Some data should be created outside the transaction (here) +INSERT INTO Orders (CustomerID, Date) + VALUES (1, "2023-01-01"); -- Start the transaction START TRANSACTION; - +INSERT INTO OrderItems (OrderID, ProductID, Count) + VALUES (1, 1, 0); +UPDATE OrderItems SET Count = Count + 1 WHERE OrderID = 1; +UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 where Name = "AwersomeProduct"; -- And some data should be created inside the transaction COMMIT; \ No newline at end of file From 75139614f6408dfed10384570ef1b0dcc872e416 Mon Sep 17 00:00:00 2001 From: Alexandr Titarenko Date: Tue, 26 May 2026 13:25:24 +0300 Subject: [PATCH 2/5] Solution1 --- task.sql | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/task.sql b/task.sql index 6df9757..39194f1 100644 --- a/task.sql +++ b/task.sql @@ -8,8 +8,7 @@ INSERT INTO Orders (CustomerID, Date) -- Start the transaction START TRANSACTION; INSERT INTO OrderItems (OrderID, ProductID, Count) - VALUES (1, 1, 0); -UPDATE OrderItems SET Count = Count + 1 WHERE OrderID = 1; + VALUES (LAST_INSERT_ID(), 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 where Name = "AwersomeProduct"; -- And some data should be created inside the transaction From 711a1e8cf6a0363e4a3ef60ba77413aabcb805fa Mon Sep 17 00:00:00 2001 From: Alexandr Titarenko Date: Tue, 26 May 2026 13:30:58 +0300 Subject: [PATCH 3/5] Solution2 --- task.sql | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/task.sql b/task.sql index 39194f1..1cc9704 100644 --- a/task.sql +++ b/task.sql @@ -2,11 +2,12 @@ USE ShopDB; -- Some data should be created outside the transaction (here) -INSERT INTO Orders (CustomerID, Date) - VALUES (1, "2023-01-01"); + -- Start the transaction START TRANSACTION; +INSERT INTO Orders (CustomerID, Date) + VALUES (1, "2023-01-01"); INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (LAST_INSERT_ID(), 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 where Name = "AwersomeProduct"; From 77a5da90f339f183486be29920ecfd8987207a6c Mon Sep 17 00:00:00 2001 From: Alexandr Titarenko Date: Tue, 26 May 2026 13:34:35 +0300 Subject: [PATCH 4/5] Solution2 --- task.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 1cc9704..299d0be 100644 --- a/task.sql +++ b/task.sql @@ -7,7 +7,7 @@ USE ShopDB; -- Start the transaction START TRANSACTION; INSERT INTO Orders (CustomerID, Date) - VALUES (1, "2023-01-01"); + VALUES (1, "2023-01-01"); INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (LAST_INSERT_ID(), 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 where Name = "AwersomeProduct"; From cfe7ae6b9ab2b004548ff16c3a04927afe8d2d7b Mon Sep 17 00:00:00 2001 From: Alexandr Titarenko Date: Tue, 26 May 2026 13:37:39 +0300 Subject: [PATCH 5/5] Solution2 --- task.sql | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 299d0be..5d59b67 100644 --- a/task.sql +++ b/task.sql @@ -3,11 +3,10 @@ USE ShopDB; -- Some data should be created outside the transaction (here) - --- Start the transaction -START TRANSACTION; INSERT INTO Orders (CustomerID, Date) VALUES (1, "2023-01-01"); +-- Start the transaction +START TRANSACTION; INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (LAST_INSERT_ID(), 1, 1); UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 where Name = "AwersomeProduct";