I could not find any tutorials on MySQL procedures that can execute multiple queries using prepared statement. Whenever i try to run such statement, i end up with errors exactly after when the first query is completed and next query is started (This will be more clear if the error provided below is seen). However, here: How to execute multiple mysql queries together in PHP?, some clues has been provided on how to achieve the same in PHP (using mysql dbms). But i would like to achieve this without connecting it to any other programming or scripting languages. Please help me, if this is possible.
Thanks in advance. The snippets of code is provided below with the error,
use student;
delimiter //
create procedure test()
begin
set @dbname = 'test_db';
set @tablesDeletion = concat('drop table if exists ',@dbname,'.table1;',
' drop table if exists ',@dbname,'.table2;',
' drop table if exists ',@dbname,'.table3;',
' drop table if exists ',@dbname,'.table4;',
' drop table if exists ',@dbname,'.table5;',
' drop table if exists ',@dbname,'.table6;');
prepare dropTmpTables from @tablesDeletion;
execute dropTmpTables;
deallocate prepare dropTmpTables;
end//
delimiter ;
call test();
Error Code: 1064. 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 'drop table if exists test_db.table1; drop table if exists test_db.table2; dr' at line 1