Lets say I have this batch:
// Insert two order lines for order #2002 (Order_Lines table)
// Update order #2002 Total Quantity (Orders table)
INSERT INTO Order_Lines (OrderID, Line, PartID, Quantity)
VALUES (2002, 1, 1234, 10);
INSERT INTO Order_Lines (OrderID, Line, PartID, Quantity)
VALUES (2002, 2, 5678, 5);
UPDATE Orders
SET TotalQty = (SELECT SUM(Quantity) FROM Order_Lines WHERE OrderID = 2002)
WHERE OrderID = 2002;
When I run this, does the server wait for each statement in the batch to finish executing before it starts executing the next statement?
What I really want to know is if the Orders table will be updated correctly if I run this batch. (If the Inserts are executed first and the Update last, it should be updated correctly.)
By the way, I’m using a SQL 2005 and a 2008 server.
Yes, you can expect the results of each statement to be available to subsequent statements.