Best way to store a script in Mysql workbench -


let's have series of tables in mysql, , of them dependent on other tables (so if didn't want force delete, have delete them in order). let's had little script delete them in order...now let's wanted run in mysql workbench, , better yet have function took in parameter (like userid) , did above... how such thing in mysql workbench in way retrieve , run code (like example if wanted delete user , other objects associated user.)

you can use stored procedure

delimiter //  create procedure delete_user(in _user_id int) begin   start transaction;   delete user_data user_id = _user_id;   -- other delete statements go here in proper order   delete users id = _user_id;   commit; end//  delimiter ; 

sample usage:

call delete_user(2); -- delete user id = 2 

here sqlfiddle demo


Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -