SQL to Update Multiple Database Table Columns With a Custom Value

On a recent project, I needed to populate a newly created column added to an existing database table with over 10 rows of record with a custom values and I’m going to show us how I did it.

Take for example, a database table that previously consisted of three columns and an additional handler_structure column was added to it via the SQL below.

ALTER TABLE table_name ADD `handler_structure` LONGTEXT NOT NULL AFTER `structure`

Notice the handler_structure columns for all row records are empty.

Sample database structure

To add a custom value say He is God, the SQL code below will do the trick.

UPDATE table_name SET handler_structure='He is God' WHERE id > 0;

The SQL above add the text or string He is God to every row with id greater than 0 thus, all the rows are affected.

La Fin!

Don’t miss out!
Subscribe to My Newsletter
Invalid email address