我们如何更改 MySQL 存储过程?


如果我们有该过程的 ALTER ROUTINE 权限,则借助**ALTER PROCEDURE **语句我们可以更改 MySQL 存储过程。为了进行演示,我们以名为“delete_studentinfo”的存储过程为例,其中具有以下的 create 语句 -

mysql> SHOW CREATE PROCEDURE Delete_studentinfo\G
*************************** 1. row ***************************
           Procedure: Delete_studentinfo
            sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_
ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `Delete_studentinfo`( IN p_id INT)
BEGIN
DELETE FROM student_info
WHERE ID=p_id;
END
character_set_client: cp850
collation_connection: cp850_general_ci
  Database Collation: latin1_swedish_ci
1 row in set (0.01 sec)

在以上结果集中,很明显存储过程“delete_studentinfo”中没有注释。现在,借助 ALTER PROCEDURE 语句,我们可以添加注释,如下所示 -

mysql> ALTER PROCEDURE Delete_studentinfo
   -> COMMENT 'deleting the record'//
Query OK, 0 rows affected (0.03 sec)

现在可以确认,在存储过程中添加了注释,借助以下查询的结果集 -

mysql> SHOW CREATE PROCEDURE Delete_studentinfo\G
*************************** 1. row ***************************
           Procedure: Delete_studentinfo
            sql_mode: ONLY_FULL_GROUP_BY,STRICT_TRANS_TABLES,NO_ZERO_IN_DATE,NO_
ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION
    Create Procedure: CREATE DEFINER=`root`@`localhost` PROCEDURE `Delete_studen
tinfo`( IN p_id INT)
   COMMENT 'deleting the record'
BEGIN
DELETE FROM student_info
WHERE ID=p_id;
END
character_set_client: cp850
collation_connection: cp850_general_ci
  Database Collation: latin1_swedish_ci
1 row in set (0.00 sec)

更新日期: 2020 年 6 月 22 日

719 次浏览

开启你的 职业生涯

通过完成课程获得认证

开始
广告