
- 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
MySQL command-line tool: How to find out number of rows affected by a DELETE?
You can use row_count() at the end for this. Let us first create a table −
mysql> create table rowAfftectedByDeleteDemo -> ( -> CustomerId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> CustomerName varchar(20) -> ); Query OK, 0 rows affected (0.86 sec)
Insert some records in the table using insert command. The query is as follows −
mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('John'); Query OK, 1 row affected (0.14 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Carol'); Query OK, 1 row affected (0.10 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Bob'); Query OK, 1 row affected (0.09 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Sam'); Query OK, 1 row affected (0.09 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('David'); Query OK, 1 row affected (0.08 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Maxwell'); Query OK, 1 row affected (0.09 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('Ramit'); Query OK, 1 row affected (0.08 sec) mysql> insert into rowAfftectedByDeleteDemo(CustomerName) values('James'); Query OK, 1 row affected (0.10 sec)
Display all records from the table using select statement. The query is as follows −
mysql> select *from rowAfftectedByDeleteDemo;
Here is the output −
+------------+--------------+ | CustomerId | CustomerName | +------------+--------------+ | 1 | John | | 2 | Carol | | 3 | Bob | | 4 | Sam | | 5 | David | | 6 | Maxwell | | 7 | Ramit | | 8 | James | +------------+--------------+ 8 rows in set (0.00 sec)
Before deleting rows from the table, the value of row_count() is as follows −
mysql> select row_count();
Here is the output −
+-------------+ | row_count() | +-------------+ | -1 | +-------------+ 1 row in set (0.00 sec)
The following is the query to delete rows from the table −
mysql> delete from rowAfftectedByDeleteDemo where CustomerId =3 || CustomerId =4 || CustomerId =5 || CustomerId =6; Query OK, 4 rows affected (0.13 sec)
After deleting rows from the table, the value of row_count() is as follows −
mysql> select row_count();
Here is the output −
+-------------+ | row_count() | +-------------+ | 4 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How can we return to windows command shell from MySQL command line tool?
- How can we get the total number of rows affected by MySQL query?
- Create a MySQL stored procedure that counts the number of rows gets affected by MySQL query?
- Which PHP function is used to give the number of rows affected by MySQL query?
- How can we write PHP script to count the affected rows by MySQL query?
- Do we require any authentication for login into MySQL command line tool?
- Aria2 – A Multi-Protocol Command-Line Download Tool for Linux
- Fping – A Command-Line Tool to Ping Hosts In Parallel on Ubuntu
- How to adjust display settings of MySQL command line?
- How to delete all rows except some in MySQL?
- How to find out number of days in a month in MySQL?
- How to open MySQL command line on Windows10?
- How to upgrade MySQL server from command line?
- How to create a database on command line in MySQL?
- How to find the MySQL data directory from command line in Windows?

Advertisements