mysql - Delete records from table if table exists -


i have lot of delete queries in production databases table not found. need simple decision on problem.

queries like

delete b.* `table` b join `another_table` u on u.key2 = b.key u.key3 <> ? 

i need like:

if table `table` exists delete b.* `table` b ... 

if need delete rows of table if latter exists, have rely on custom stored procedure think. that:

-- define procedure create procedure delete_if_exists(in tbl char(80)) begin     if @tbl in (select table_name information_schema.tables table_schema = "db_2_44afb7")             set @query = concat("delete ", @tbl);         prepare stmt @query;         execute stmt;     end if; end //  -- use call delete_if_exists("mytable"); call delete_if_exists("myothertable"); 

see http://sqlfiddle.com/#!2/2ee190/3 example.
of course, adjust "delete from",... part fit specific needs.


Comments

Popular posts from this blog

basic authentication with http post params android -

vb.net - Virtual Keyboard commands -

css - Firefox for ubuntu renders wrong colors -