MySQL – Update Column Value for All Entries in Table

To update values of a column for all records in a table in MySQL, use SQL UPDATE statement.

In this tutorial, we will learn the syntax of SQL UPDATE statement, and how to use it to update a field/column for all rows in the table, with examples.

The following is a simple syntax of UPDATE statement to update a column value for all entries.

UPDATE table_name SET column_name = new_value;
ADVERTISEMENT

where

  • table_name is the table name in which we would like to update.
  • column_name is the name of column whose value for all the rows in the table has to be updated.
  • new_value will be assigned to the specified column for all rows in table.

Example

In the following example, we will consider a table students and update the column rollno to -1 for all the entries.

SQL Query

UPDATE students SET rollno = -1;

“students” table before UPDATE

name	rollno
Arjun	14
Manish	15
Vina	16

“students” table after UPDATE

name	rollno
Arjun	-1
Manish	-1
Vina	-1