
- 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
Implement DELETE query in MySQL stored procedure
You can use stored procedure and can pass the value via parameter. Let us first create a table −
mysql> create table DemoTable1464 -> ( -> Id int, -> FirstName varchar(20) -> ); Query OK, 0 rows affected (0.51 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1464 values(101,'Chris Brown'); Query OK, 1 row affected (0.11 sec) mysql> insert into DemoTable1464 values(102,'John Doe'); Query OK, 1 row affected (0.09 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1464;
This will produce the following output −
+------+-------------+ | Id | FirstName | +------+-------------+ | 101 | Chris Brown | | 102 | John Doe | +------+-------------+ 2 rows in set (0.00 sec)
Here is the query to implement delete query in stored procedure −
mysql> DELIMITER // mysql> CREATE PROCEDURE delete_demo(IN local_Id int, IN local_Name varchar(20)) -> BEGIN -> delete from DemoTable1464 -> where Id=local_Id and -> FirstName=local_Name; -> END // Query OK, 0 rows affected (0.24 sec) mysql> DELIMITER ;
Now you can call the stored procedure using CALL command −
mysql> call delete_demo(102,'John Doe'); Query OK, 1 row affected, 1 warning (0.11 sec)
Let us check the table records once again −
mysql> select * from DemoTable1464;
This will produce the following output −
+------+-------------+ | Id | FirstName | +------+-------------+ | 101 | Chris Brown | +------+-------------+ 1 row in set (0.00 sec)
- Related Articles
- Implement Conditional MySQL Query in a stored procedure?
- Implement Dynamic SQL query inside a MySQL stored procedure?
- Implement If else in stored procedure in MySQL?
- How to correctly implement conditions in MySQL stored procedure?
- MySQL Sum Query with IF Condition using Stored Procedure
- How to correctly implement END IF statement in a MySQL Stored Procedure?
- Get database name from a query implemented in a MySQL Stored Procedure?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
- MySQL stored procedure return value?
- MySQL stored-procedure: out parameter?
- How can I create a stored procedure to delete values from a MySQL table?
- View stored procedure/function definition in MySQL?
- Set conditions in a MySQL stored procedure
- Display description of MySQL stored procedure
- Create a MySQL stored procedure that counts the number of rows gets affected by MySQL query?

Advertisements