using commit / rollback in SQL script

Discussion of open issues, suggestions and bugs regarding database management and administration tools for MySQL
Locked
john_kuiper
Posts: 19
Joined: Tue 15 May 2012 09:34

using commit / rollback in SQL script

Post by john_kuiper » Tue 15 May 2012 09:55

I'm creating a SQL regular to update another database with te same structure. Some queries are collected statements to put data in tables (several INSERTS). These data must only be committed when the collected queries are done. The script looks like this:

Code: Select all

set autocommit = 0

insert into table1 values ('table1_field1', 'table1_field2', 'table1_field3');
insert into table2 values ('table1_field1', 'table2_field2', 'table2_field3');
insert into table3 values ('table1_field1', 'table2_field2', 'table3_field3');
commit work;

insert into table4 values (1,2,3,4,5,6,7,8,9);
commit work;

set autocommit = 1
If table1 or table2 or table3 gets an error a rollback must be done and the end of the script must be reached. Is this possible in the script.

alexa

Re: using commit / rollback in SQL script

Post by alexa » Tue 15 May 2012 13:57

Since the questions is not connected with our product, we suggest you to search for the answer in the Internet as we provide technical support only on our products.

Locked