Code360 powered by Coding Ninjas X Naukri.com. Code360 powered by Coding Ninjas X Naukri.com
Table of contents
1.
Introduction
2.
MYSQL
3.
What is UPDATE Query in MySQL?
4.
Update Query Syntax
5.
Update Query Example
5.1.
Create Database
5.2.
Create Table
5.3.
Insert Values
5.4.
Update Column
6.
Frequently Asked Questions
6.1.
What is UPDATE query in MySQL?
6.2.
How to UPDATE data in a table in MySQL?
6.3.
How do I UPDATE my MySQL?
7.
Conclusion
Last Updated: Mar 27, 2024
Easy

Update Query in MySQL

Author yuvatimankar
0 upvote
Master Python: Predicting weather forecasts
Speaker
Ashwin Goyal
Product Manager @

Introduction

With the times increasing, the importance of gathering, evaluating, and managing the data is increased significantly. The concept of data is continuously evolving and transforming in the world of business. Due to this, the need to manage the data is also increasing, giving rise to the database management system concept. 

Update query in MySQL

Database management systems(DBMS) are highly important for corporations in managing multiple databases and retrieving relevant information. Also, it is helpful in organizing data in a way that it can be accessed easily. This article will cover a relational database, i.e., MySQL, and update query in MySQL. So let's get started with it!

MYSQL

MySQL is a relational database management system (RDMS) based on SQL, which is highly popular for accessing and managing the relational database. MySQL is free and open-source software supported by Oracle Company. MySQL is scalable, fast, and easy to use compared to Oracle Database and Microsoft SQL Server.

MySQL defined the database relationships in tabular form (collection or rows and columns). It consists of various queries which help in managing the database and manipulating data. These queries are update records, delete records, create tables, drop tables, insert records, select records, etc. In this article, we will only focus on the Update query.

Get the tech career you deserve, faster!
Connect with our expert counsellors to understand how to hack your way to success
User rating 4.7/5
1:1 doubt support
95% placement record
Akash Pal
Senior Software Engineer
326% Hike After Job Bootcamp
Himanshu Gusain
Programmer Analyst
32 LPA After Job Bootcamp
After Job
Bootcamp

What is UPDATE Query in MySQL?

An update query in MySQL is used to modify or update rows in a table. It is a DML statement. In real life, over a period of time, records are changed. So, we are required to change the values of the table; also, in such cases, we need to use the UPDATE query. This command can be used to update single or multiple fields at the same time. 

The UPDATE query is used along with the SET and WHERE conditions. It can also be used for updating a MySQL table with values from another table.

Update Query Syntax

The common syntax for the Update query in MySQL is as follows:

UPDATE `table_name` SET `column_name` = `new_value' [WHERE condition];


Where,

Parameter Description
table-name It is the name of the table in which we want to update the changes.
column-name It is the name of a column where we want to make an updation with the new value with the help of the SET clause. If we are updating multiple columns, then we have to separate the columns with a comma by stating the value in each column.
WHERE condition It is used to describe the row name where we will make the changes. MySQL will updates all the rows if we miss this condition.

Note: while entering the updated values, strings should be in single quotes. There is no need to add quotation marks for numeric values. The format of the Date should be ‘YYYY-MM-DD’, and it should also be in single quotes.

Update Query Example

An update query is used when the existing table is required to be modified; in that case, we can use an update query to make the changes in the existing MySQL table. Let us now see an example to Update the existing table.

Suppose we have a database named "CODING" in which we have a table named "EMPLOYEE" in which we have the following attributes:  Id, FirstName, LastName, Phone, Email.

Create Database

The command for creating a Database named “CODING”:

CREATE DATABASE CODING;

Create Table

The command for creating a table named “EMPLOYEE”:

CREATE TABLE EMPLOYEE(
ID INT(10) PRIMARY KEY, 
FIRSTNAME VARCHAR(25) NOT NULL, 
LASTNAME VARCHAR(25) NOT NULL,
PHONE INT(10) NOT NULL,
EMAIL VARCHAR(30) NOT NULL);


Output:

Table creation

Insert Values

The command for inserting Values into the table:

INSERT INTO EMPLOYEE(ID, FIRSTNAME, LASTNAME, PHONE, EMAIL)VALUES (1,' JEFF', 'MARTIN',873606587,'Jeffmartin1@gmail.com'),(2, 'SUMIT', 'MANDAL',78761400,'hisomu@gmail.com');
Inserting Values

Update Column

Now, we are going to update the data within the employee table.The following query will update the phone number and email of Sumit:

UPDATE EMPLOYEE SET PHONE = 745497635, EMAIL= ‘Sumitmandal@gmail.com’ WHERE ID=2;

 

Output:

Update column

In this way, we can update the changes we want to reflect in our existing database. We hope that now you have an overview of this topic clearly.

Frequently Asked Questions

What is UPDATE query in MySQL?

The UPDATE query in MySQL modifies existing records in a table, allowing you to change values in specific columns based on specified conditions.

How to UPDATE data in a table in MySQL?

Use the UPDATE statement with SET to modify data. Specify the new values and conditions to identify the rows to be updated.

How do I UPDATE my MySQL?

To update MySQL itself, download and install the latest version from the official MySQL website, following the provided instructions for your operating system.

Conclusion

In this article, we have discussed the Update query in MySQL. We started with the introduction to data and database; then we saw what MySQL is, Update query in MySQL, and some examples to better understand the query. 

We hope this blog has helped you enhance your knowledge of the update query in MySQL. If you want to learn more, then check out our articles:

Refer to our guided paths on Coding Ninjas Studio to upskill yourself in Data Structures and AlgorithmsCompetitive ProgrammingJavaScriptSystem Design, and many more! If you want to test your competency in coding, you may check out the mock test series and participate in the contests hosted on Coding Ninjas Studio! But suppose you have just started your learning process and are looking for questions asked by tech giants like Amazon, Microsoft, Uber, etc.. In that case, you must have a look at the problemsinterview experiences, and interview bundles for placement preparations.

Nevertheless, consider our paid courses to give your career an edge over others!

Do upvote our blogs if you find them helpful and engaging!

Previous article
What is View in SQL
Next article
MySQL Connection
Live masterclass