From 739c23cb553161f92ed71b1ac87296e3bf9caa83 Mon Sep 17 00:00:00 2001 From: Oleh K Date: Fri, 10 Jul 2026 12:45:29 +0200 Subject: [PATCH 1/2] Solution --- task.sql | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/task.sql b/task.sql index 8adf22b..c8ae97b 100644 --- a/task.sql +++ b/task.sql @@ -2,10 +2,19 @@ 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; -- And some data should be created inside the transaction -COMMIT; \ No newline at end of file +INSERT INTO OrderItems (OrderID, ProductID, Count) +VALUES (LAST_INSERT_ID(), 1, 1); + +UPDATE Products +SET WarehouseAmount = WarehouseAmount - 1 +WHERE ID = 1; + +COMMIT; From 58747622ed7d03e02a6505609af8966a753c510a Mon Sep 17 00:00:00 2001 From: Oleh K Date: Fri, 10 Jul 2026 12:50:14 +0200 Subject: [PATCH 2/2] upd: added order_count --- task.sql | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/task.sql b/task.sql index c8ae97b..7e0d196 100644 --- a/task.sql +++ b/task.sql @@ -5,16 +5,17 @@ USE ShopDB; INSERT INTO Orders (CustomerID, Date) VALUES (1, '2023-01-01'); +SET @order_count = 1; + -- Start the transaction START TRANSACTION; --- And some data should be created inside the transaction - +-- And some data should be created inside the transaction INSERT INTO OrderItems (OrderID, ProductID, Count) -VALUES (LAST_INSERT_ID(), 1, 1); +VALUES (LAST_INSERT_ID(), 1, @order_count); UPDATE Products -SET WarehouseAmount = WarehouseAmount - 1 +SET WarehouseAmount = WarehouseAmount - @order_count WHERE ID = 1; COMMIT;