
- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
How can we alter a MySQL stored procedure?
If we have ALTER ROUTINE privileges for the procedure then with the help of ALTER PROCEDURE statement we can alter a MySQL stored procedure. To demonstrate it we are taking an example of a stored procedure named ‘delete_studentinfo’ which have the following create a statement −
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)
In the above result set, it is clear that there is no comment in the stored procedure ‘delete_studentinfo’. Now, with the help of ALTER PROCEDURE statement, we can add a comment as follows −
mysql> ALTER PROCEDURE Delete_studentinfo -> COMMENT 'deleting the record'// Query OK, 0 rows affected (0.03 sec)
Now, it can be confirmed, that comments have been added in the stored procedure, with the help of result set of the following query −
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)
- Related Articles
- How can we alter a MySQL stored function?
- How can we drop a MySQL stored procedure?
- How can we invoke MySQL stored procedure?
- How can we write MySQL handler in a stored procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- What is stored procedure and how can we create MySQL stored procedures?
- How can we alter table to add MySQL stored GENERATED COLUMNS?
- How can we handle a result set inside MySQL stored procedure?
- How can we perform ROLLBACK transactions inside a MySQL stored procedure?
- How can we perform START transactions inside MySQL stored procedure?
- How can we perform COMMIT transactions inside MySQL stored procedure?
- How can we create MySQL stored procedure to calculate the factorial?
- How can we see the source code of a particular MySQL stored procedure?
- How can we use prepared statements in a stored procedure?
- How can we write MySQL stored procedure to select all the data from a table?

Advertisements