简体   繁体   中英

mysql Stored Procedure, Query to check if exists or not

i am looking for a possible MySqL query which will check to see if a stored procedure exists on the database server, if it does great Return, if it doesnt then i can insert it using c#.

any help is appreciated

Vade

You can do this:

SELECT * FROM `information_schema`.`ROUTINES` where specific_name = 'my_procedure_name' and routine_schema = 'my_schema'

..and if it exists, should get a result. However, keep in mind that on the majority of shared hosting mysql services, routines, triggers and so on are not normally allowed to be created. If it's your own server, no problem ;)

On MS SQL you can perform the following query:

if exists
(
    select name from sysobjects
    where name = 'function_name' and type = 'fn'
)
begin
    drop function function_name
end
go

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM