4

I want to delete all procedures from my MySQL database sbnmaster. How should I write a query for this?

Dharman
  • 26,923
  • 21
  • 73
  • 125
learner
  • 2,419
  • 3
  • 20
  • 22
  • 2
    http://stackoverflow.com/questions/3027832/drop-all-stored-procedures-in-mysql-or-using-temporary-stored-procedures – gmaliar Aug 25 '11 at 09:26

2 Answers2

9

Try this

USE sbnmaster;

SELECT CONCAT("DROP PROCEDURE IF EXISTS ",SPECIFIC_NAME) AS StorePrecedure 
FROM information_schema.ROUTINES R 
WHERE R.ROUTINE_TYPE = "PROCEDURE" 
AND R.ROUTINE_SCHEMA = DATABASE(); 
Rahul
  • 73,987
  • 13
  • 62
  • 116
  • I had to add a semicolon to the concat to get it to work with several procs: `SELECT CONCAT("DROP PROCEDURE IF EXISTS ",SPECIFIC_NAME,";") AS StorePrecedure ` – BenR Feb 18 '14 at 20:24
7

Not sure that it is correct, but seems it works -

DELETE FROM mysql.proc WHERE db = 'sbnmaster' AND type = 'PROCEDURE';
Devart
  • 115,199
  • 22
  • 161
  • 180