tags:

views:

19

answers:

2

I have executing 10 query in my stored procedure.

In case after executing the 5 Th query my database get interrupted and its stooped the execution.

My first 5 query updated in database.so i have to rollback all the 5 query's execution.

How to solve this kind of problems?

+1  A: 

Use InnoDB transactions. START TRANSACTION ... COMMIT. See doc.

Piotr Pankowski
+2  A: 

The default MySQL table type is MyISAM, which doesn't support transactions. Thankfully there is another table type InnoDB, which does support transactions. Converting the table type is easy enough:

http://dev.mysql.com/doc/refman/5.0/en/converting-tables-to-innodb.html

And when making queries do this:

START TRANSACTION

// do whatever queries you want to

// if there are no errors
COMMIT

// if there are errors
ROLLBACK

After a rollback, your db will return to the state it was at the point you called START TRANSACTION. This tutorial should help some more:

http://www.devshed.com/c/a/MySQL/Using-Transactions-In-MySQL-Part-1/

Note: You can't use FULLTEXT queries with InnoDB tables.

MatW
Good response, and clear ideas.....got it
Ayyappan.Anbalagan
Thx. :) Not sure if my answer is clear about this, but whether the transaction performs a COMMIT or a ROLLBACK isn't an automatic thing; you have to perform the error checks and take whichever action seems appropriate.
MatW