
- 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
Does UPDATE overwrite values if they are identical in MySQL
No, MySQL UPDATE won’t overwrite values if they are identical. Let us first create a table −
mysql> create table DemoTable ( StudentId int, StudentMathMarks int, StudentMySQLMarks int ); Query OK, 0 rows affected (0.46 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values(1,56,78); Query OK, 1 row affected (0.21 sec) mysql> insert into DemoTable values(2,88,99); Query OK, 1 row affected (0.15 sec) mysql> inse rt into DemoTable values(3,34,98); Query OK, 1 row affected (0.13 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-----------+------------------+-------------------+ | StudentId | StudentMathMarks | StudentMySQLMarks | +-----------+------------------+-------------------+ | 1 | 56 | 78 | | 2 | 88 | 99 | | 3 | 34 | 98 | +-----------+------------------+-------------------+ 3 rows in set (0.00 sec)
Following is the query to update values. The values set are already present in that specific column i.e. student id 2, math marks 88 and SQL marks 99 for student id 2 −
mysql> update DemoTable set StudentId=2,StudentMathMarks=88,StudentMySQLMarks=99 where StudentId=2; Query OK, 0 rows affected (0.00 sec) Rows matched: 1 Changed: 0 Warnings: 0
Look at the above UPDATE command, the output, 0 rows affected means UPDATE does not overwrite values if they are identical.
- Related Articles
- Update in MongoDB and prevent overwrite?
- Check if MySQL entry exists and if it does, how to overwrite other columns?
- Update multiple values in a table with MySQL IF Statement
- Does MySQL update with regexp possible?
- Update with multiple values in MySQL WHERE clause
- MySQL UPDATE using IF condition
- Check if two lists are identical in Python
- How can we update values in a MySQL table?
- How can I update the boolean values in MySQL?
- How can we update any value in MySQL view as we can update the values in MySQL table?
- MySQL update column to NULL for blank values
- Check if tuple and list are identical in Python
- How do I update NULL values in a field in MySQL?
- MySQL queries to update date records with NULL values
- Python - Check if all elements in a list are identical

Advertisements