From 8aae8cffd2d8f9d79625bafff082f2aafa07fa31 Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 31 Mar 2026 16:20:07 +0200 Subject: [PATCH 1/2] sol1 --- task.sql | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/task.sql b/task.sql index 8adf22b..e0f154f 100644 --- a/task.sql +++ b/task.sql @@ -1,11 +1,15 @@ --- Use our database -USE ShopDB; +USE ShopDB; --- Some data should be created outside the transaction (here) +START TRANSACTION; --- Start the transaction -START TRANSACTION; +INSERT INTO Orders (CustomerID, Date) + VALUES (1, '2023-01-10'); --- And some data should be created inside the transaction +INSERT INTO OrderItems (OrderID, ProductID, Count) + VALUES (LAST_INSERT_ID(), 1, 1); -COMMIT; \ No newline at end of file +UPDATE Products +SET WarehouseAmount = WarehouseAmount - 1 +WHERE ID = 1; + +COMMIT; From 6b31c99de09402778afa202d1824c012deb9db6c Mon Sep 17 00:00:00 2001 From: Dmytro Date: Tue, 31 Mar 2026 16:29:36 +0200 Subject: [PATCH 2/2] sol2 --- task.sql | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/task.sql b/task.sql index e0f154f..ed4e5e3 100644 --- a/task.sql +++ b/task.sql @@ -1,15 +1,15 @@ USE ShopDB; -START TRANSACTION; - INSERT INTO Orders (CustomerID, Date) - VALUES (1, '2023-01-10'); + VALUES(1, '2023-01-20'); + +START TRANSACTION; INSERT INTO OrderItems (OrderID, ProductID, Count) VALUES (LAST_INSERT_ID(), 1, 1); UPDATE Products -SET WarehouseAmount = WarehouseAmount - 1 -WHERE ID = 1; + SET WarehouseAmount = WarehouseAmount - 1 + WHERE ID = 1; COMMIT;