MySQL Affected Rows


 

MySQL Affected Rows

This example illustrates how to show the affected rows of the table.

This example illustrates how to show the affected rows of the table.

MySQL Affected Rows

This example illustrates how to show the affected rows of the table.

In this example we create table "price" with 'assetid', 'date', 'open', 'high', 'low', 'close' and 'volume' field.

 

Query

 

 CREATE TABLE `price` (
   `assetid` int(11) NOT NULL default '0',
   `date` date NOT NULL default '0000-00-00',
   `open` double default NULL,
   `high` double default NULL,
   `low` double default NULL,
   `close` double default NULL,
   `volume` bigint(20) default NULL,
   PRIMARY KEY  (`assetid`,`date`)
 ) ENGINE=InnoDB DEFAULT CHARSET=latin1;

 

Output

 

Query OK, 0 rows affected (0.08 sec)

 

Here update a table "price".

Query

 

update price set open=3 where assetid=1;

 

Output

 

Query OK, 0 rows affected (0.00 sec)
Rows matched: 1  Changed: 0  Warnings: 0

 

Here execute Row_Count() function to count the rows.

Query

 

 select Row_Count();

 

Output

 

+-------------+
| Row_Count() |
+-------------+
| 0           |
+-------------+
1 row in set (0.00 sec)

 

Once-Again update the table.

Query

 

 update price set open=3 where assetid=2;

 

Output

 

Query OK, 1 row affected (0.03 sec)
Rows matched: 1  Changed: 1  Warnings: 0

 

Again execute Row_Count() function.

Query

 

select Row_Count();

 

Output

 

+-------------+
| Row_Count() |
+-------------+
| 1           |
+-------------+
1 row in set (0.00 sec)

 

Execute Row_Count() function with Row_Affected keyword.

Query

 

select Row_Count() as Row_Affected;

 

Output

 

+--------------+
| Row_Affected |
+--------------+
| 1            |
+--------------+
1 row in set (0.00 sec)

 

Ads