From e509a0710ebbd79dff9ca9ecebf00521bc86b2e4 Mon Sep 17 00:00:00 2001 From: Ivan Sotsenko Date: Wed, 13 May 2026 21:02:40 +0200 Subject: [PATCH 1/2] Solution --- task.sql | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 8adf22b..39d6f3a 100644 --- a/task.sql +++ b/task.sql @@ -1,11 +1,18 @@ -- Use our database -USE ShopDB; - --- Some data should be created outside the transaction (here) +USE ShopDB; -- Start the transaction START TRANSACTION; +INSERT INTO Orders(CustomerID, Date) + VALUES(1, '2026-05-13'); + +SET @orderId = LAST_INSERT_ID(); + +INSERT INTO OrderItems(OrderID, ProductID, Count) + VALUES(@orderId, 1,1); + +UPDATE Products SET WarehouseAmount = WarehouseAmount - 1 WHERE ID = 1; -- And some data should be created inside the transaction COMMIT; \ No newline at end of file From 9141a4077abc151ba409790aa0d2981bc70e9438 Mon Sep 17 00:00:00 2001 From: Ivan Sotsenko Date: Wed, 13 May 2026 21:09:03 +0200 Subject: [PATCH 2/2] Move INSERT INTO Orders outside transaction --- task.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/task.sql b/task.sql index 39d6f3a..429d23c 100644 --- a/task.sql +++ b/task.sql @@ -1,12 +1,12 @@ -- Use our database USE ShopDB; --- Start the transaction -START TRANSACTION; - INSERT INTO Orders(CustomerID, Date) VALUES(1, '2026-05-13'); +-- Start the transaction +START TRANSACTION; + SET @orderId = LAST_INSERT_ID(); INSERT INTO OrderItems(OrderID, ProductID, Count)