I have 7 SQL Query to do a task like this :
1. UPDATE Customer SET CustomerService = 'perta' WHERE FirstName = 'john';
2. UPDATE Customer SET Flag = 1 WHERE OrderNum BETWEEN 2 AND 29;
3. UPDATE Customer SET PurchaseNum = PurchaseNum + 60 WHERE OrderNum BETWEEN 2 AND 29;
4. UPDATE Customer SET OrderNum = OrderNum + 60 WHERE OrderNum BETWEEN 2 AND 29;
5. UPDATE Customer SET PurchaseNum = PurchaseNum - 28 WHERE (PurchaseNum > 29 AND PurchaseNum <= 89) AND (Flag <> 1);
6. UPDATE Customer SET OrderNum = OrderNum - 28 WHERE (OrderNum > 29 AND OrderNum <= 89) AND (Flag <> 1);
7. UPDATE Customer SET Flag = 0 WHERE OrderNum BETWEEN 62 AND 89;
is it possible to ‘compress’ those SQL Queries into 1 Query?
because I’m afraid that user cancel the process by pressing the ESC button (after he/she press the SUBMIT button), those sequence will be broken in the middle and my table will be messy as well.
If you are using MySQL then see this link it shows you how to implement transaction in MySQL.
http://dev.mysql.com/doc/refman/5.5/en/commit.html
Transaction helps us in many scenario and you are handling one of them where you want to update multiple database tables.