Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Multiple transactions can be added using a single SQL script by using the BEGIN TRANSACTION, COMMIT, and ROLLBACK statements to group the transactions together. Here's an example:

BEGIN TRANSACTION;

--Add transaction 1-- INSERT INTO customers (name, email) VALUES ('John Doe', 'johndoe@email.com');

--Add transaction 2-- UPDATE orders SET orderstatus = 'completed' WHERE customerid = 1;

COMMIT;

In this example, multiple transactions are grouped together using the BEGIN TRANSACTION statement. If all the transactions in the script complete successfully, the COMMIT statement is executed to commit all the changes to the database. If any of the transactions fail, the ROLLBACK statement can be used to undo all the changes made in the current transaction and return the database to its previous state. It is important to use transactions when making multiple changes to the database to ensure the data remains consistent and error-free.