mysql 删除存储过程权限 mysql删除存储过程语句_db2 删除存储过程


一.查看存储过程和函数

1. show status语句查看存储过程和函数的状态

mysql中可以通过show status语句查看存储过程和存储函数的状态。语法:

show {procedure|function} status [like ‘pattern’];

procedure:表示查询存储过程;

function:表示查询存储函数;

like ‘parttern’:参数用来匹配存储过程或函数的名称;

下面查询名为name_pro_employee的存储过程的状态。


mysql 删除存储过程权限 mysql删除存储过程语句_db2 删除存储过程_02


2. show create 语句查看存储过程和函数的定义

mysql中通过show create 语句查看存储过程和函数的状态。语法:

show create{procedure|function} sp_name;

procedure:参数表示查询存储过程;

function:参数表示查询存储函数;

sp_name:参数表示存储过程或函数的名称;


mysql 删除存储过程权限 mysql删除存储过程语句_mysql definer_03


注:show status 语句只能查看存储过程或函数是操作哪一个数据库、存储过程或函数的名称、类型、谁定义的、创建和修改时间、字符编码等信息。

3. 从information_schema.Routines表中查看存储过程

存储过程和函数的信息存储在information_schema数据库下的routines表中。可以通过查询该表的记录来查询存储过程和函数的信息。语法:

select * from information_schema.routines where routine_name=’sp_name’;

routine_name:字段中存储的是存储过程和函数的名称;

sp_name:参数表示存储过程或函数的名称;

下面从routines表中查询名为name_pro_employee的存储过程信息。


mysql 删除存储过程权限 mysql删除存储过程语句_db2 删除存储过程_04


注:在information_schema数据库下的routines表中,存储着所有存储过程和函数的定义。如果使用select语句查询routines表中的存储过程和函数的定义时,一定要使用routine_name字段指定存储过程或函数的名称,否则,将查询所有的存储过程或函数的定义。

二.修改存储过程和函数

修改存储过程和函数是指修改已经定义好的存储过程和函数。mysql中通过alter procedure语句来修改存储过程。通过alter function语句来修改存储函数。

mysql中存储过程和存储函数的修改语法:

alter {procedure|function} sp_name [characteristic…]
characteristic:{contains sql|no sql|reads sql data|modifies sql data}|sql security{definer|invoker}|comment ‘string’

sp_name:表示存储过程和存储函数的名称;

characteristic:指定存储函数的特性;

contains:SQL表示子程序包含SQL语句,但不包含读或写数据的语句;

no SQL:表示子程序中不包含SQL语句;

reads SQL data:表示子程序中包含读数据的语句;

modifies sql data:表示子程序中包含写数据的语句;

SQL security{definer|invoker}:指明谁有权限执行;

definer:表示只有定义着才能执行;

invoker:表示调用者可以执行;

comment ‘string’:是注释信息;

下面修改存储过程name_pro_employee的定义。将读写权限改为modifies sql data,并指明调用者可以执行;

alter procedure name_pro_employee modifies sql data sql security invoker;


mysql 删除存储过程权限 mysql删除存储过程语句_mysql存储过程返回结果集_05


下面修改存储函数

修改num_fun_employee的定义。将读写权限改为reads SQL data,并加上注释信息’find name’。


mysql 删除存储过程权限 mysql删除存储过程语句_db2 删除存储过程_06


alter function num_fun_employee reads sql data comment ‘find name’;


mysql 删除存储过程权限 mysql删除存储过程语句_mysql function_07


三.删除存储过程和函数

删除存储过程和存储函数是指数据库中已经存在的存储过程和函数。语法:

drop procedure语句删除存储过程;

drop function语句删除存储函数;

drop {procedure|function} sp_name;

下面删除存储过程name_pro_employee和存储函数num_fun_employee。

drop procedure name_pro_employee;


mysql 删除存储过程权限 mysql删除存储过程语句_mysql存储过程返回结果集_08


drop function num_fun_employee;


mysql 删除存储过程权限 mysql删除存储过程语句_db2 删除存储过程_09


查询information_schema数据库下的routines表来确认是否删除成功;

select * from information_schema.routines where routine_name=’name_pro_employee’ or routine_name=’num_fun_employee’;


mysql 删除存储过程权限 mysql删除存储过程语句_mysql function_10