Ask Your Question
1

How can multiple transactions be added using a single SQL script?

asked 2022-08-29 11:00:00 +0000

huitzilopochtli gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
2

answered 2021-05-13 23:00:00 +0000

nofretete gravatar image

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.

edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2022-08-29 11:00:00 +0000

Seen: 11 times

Last updated: May 13 '21