I have a method where it starts a transaction with the following queries:
INSERT INTO order_item (item_no, order_id)
SELECT TOP " + Quantity + " item_no, @order_id
FROM items where status = 'Unused'
once the first insert command has been executed, I want to update all the item_no in the items table that was inserted into order_item in the previous command:
UPDATE items (select item_no from order_item where order_id = @order_id)
SET status = 'Used'
I am worried that if other transaction starts while an existing one is running, they could potentially choose kit numbers that supposed to be marked as ‘Used’ since the first transaction might be committed for the items to be marked as “Used”.
Would appreciate if anyone can give some advice on this issue.
Thanks!
Do it all in one with some composable DML?