- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I detect if the ON UPDATE event fired with query in MySQL?
You can detect with the help of row_count(). If the row_count() returns 1 that means it is a new record. If it returns 2, that means the ON UPDATE event is fired with query. Following is the syntax −
select row_count();
Let us first create a table −
mysql> create table DemoTable1512 -> ( -> Value int , -> UNIQUE(Value) -> ); Query OK, 0 rows affected (0.60 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1512 values(90) on duplicate key update Value=Value+10; Query OK, 1 row affected (0.09 sec)
Now you can check the on update event is fired with the help of above query −
mysql> select row_count();
This will produce the following output −
+-------------+ | row_count() | +-------------+ | 1 | +-------------+ 1 row in set (0.00 sec)
It returns 1 that means no.
Now you can insert same records again in the table using insert command −
mysql> insert into DemoTable1512 values(90) on duplicate key update Value=Value+10; Query OK, 2 rows affected (0.12 sec)
Now you can check the on update event is fired with the help of above query −
mysql> select row_count();
This will produce the following output −
+-------------+ | row_count() | +-------------+ | 2 | +-------------+ 1 row in set (0.00 sec)
- Related Articles
- How do I detect if a table exist in MySQL?
- How do I view events fired on an element in Chrome?
- How do I remove ON UPDATE CURRENT_TIMESTAMP from an existing column in MySQL?
- How do I update images on a Tkinter Canvas?
- How do I update NULL values in a field in MySQL?
- How do I update the decimal column to allow more digits in MySQL?
- How do I split a numerical query result in MySQL?
- How to bulk update MySQL data with a single query?
- How do I insert multiple values in a column with a single MySQL query?
- Update two columns with a single MySQL query
- How do I $set and $push in single update with MongoDB?
- How do I write not greater than in a MySQL query?
- MySQL query to update different fields based on a condition?
- How do I handle the window close event in Tkinter?
- How can I update the boolean values in MySQL?

Advertisements