Home Tutorial Php Sql MySQL Affected Rows

 
 

MySQL Affected Rows
Posted on: December 9, 2010 at 12:00 AM
Advertisement
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)

 

Advertisement

Related Tags for MySQL Affected Rows:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com