MySQL – Update Empty String Values of a Column in Table
To update empty string values of a column in a table in MySQL, use SQL UPDATE statement with WHERE clause and the condition being the column empty.
The following is a simple syntax of UPDATE statement with WHERE clause to update a column value if its value is an empty string.
UPDATE table_name SET column_name = new_value WHERE column_name = '' ;
where
ADVERTISEMENT
- table_name is the table name in which we would like to update.
- column_name is the name of column whose value has to be checked if it is empty string, and updated.
- new_value will be assigned to the specified column for all rows in table.
Examples
In the following example, we will consider a table students
and update the column name
to Not Avaiable
if name
is empty.
“students” table before UPDATE
name rollno Arjun 14 Manish 15 Vina 16 17 18
SQL Query
UPDATE students SET name = 'Not Available' WHERE name = '';
Response
2 row(s) affected Rows matched: 2 Changed: 2 Warnings: 0
“students” table after UPDATE
name rollno Arjun 14 Manish 15 Vina 16 Not Available 17 Not Available 18