When executing:
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK;
SELECT 1;
END;
DECLARE EXIT HANDLER FOR SQLWARNING
BEGIN
ROLLBACK;
SELECT 1;
END;
-- delete all users in the main profile table that are in the MaineU18 by email address
DELETE FROM ap_form_1 WHERE element_5 IN (SELECT email FROM MaineU18);
-- delete all users from the MaineU18 table
DELETE from MaineU18;
COMMIT;
END;
I get:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'e1:
DECLARE EXIT HANDLER FOR SQLEXCEPTION
BEGIN
ROLLBACK' at line 2
Any ideas? Thanks.
UPDATE 2:
I have tried putting the script into a PROCEDURE:
DELIMITER |
DROP PROCEDURE IF EXISTS temp_clapro|
CREATE PROCEDURE temp_clapro()
BEGIN
DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING ROLLBACK;
SET AUTOCOMMIT=0;
-- delete all users in the main profile table that are in the MaineU18 by email address
DELETE FROM ap_form_1 WHERE element_5 IN (SELECT email FROM MaineU18);
-- delete all users from the MaineU18 table
DELETE from MaineU18;
COMMIT;
SET AUTOCOMMIT=1;
END
|
DELIMITER ;
CALL temp_clapro();
I am still having issues:
Query OK, 0 rows affected (0.00 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
Query OK, 0 rows affected (2.40 sec)
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'END;
|
DELIMITER ;
CALL temp_clapro()' at line 1
UPDATE 3:
It seems that many of my problems are coming from the fact that I am running the script from a file using the "SOURCE" command. If I only have the DROP and CREATE commands in the file and run the DELIMITER and CALL commands outside the file, everything works without error.
Is there away to run this from a single script file?