How do I bulk edit fields in my mysql database

I have a field in my users table and I want to change about 1000 entries from "null" to a specific zip code ... is there a query that I can run?

+3
source share
4 answers

You can first see what needs to be updated:

SELECT * FROM yourtable WHERE specificfield IS NULL

The script update is performed in the same way as:

UPDATE yourtable SET specificfield='$newvalue' WHERE specificfield IS NULL

Where:
yourtable is the name of the table you want, with the cells you want to update.
specificfield is the name of the field you want to update.
$ newvalue - the new value for the field (in quotation marks, since this is probably a string - I need to avoid this string).

note: , (, specificfield = '00000')

: ( )

SELECT * FROM yourtable 
WHERE (specificfield IS NULL OR specificfield=0) AND userid<1000

UPDATE yourtable SET specificfield='$newvalue' 
WHERE (specificfield IS NULL OR specificfield=0) AND userid<1000

where , , where .

+8

, NULL:

UPDATE your_table 
SET    your_field_name = 'ZIP CODE' 
WHERE  your_field_name IS NULL;

'ZIP CODE' .

+2
UPDATE `tablename` SET `fieldname` = 'ZIPCODE' WHERE `fieldname` is null;
+1
source

UPDATE tablename SET fieldname = 'ZIPCODE' WHERE fieldname IS NULL

+1
source

Source: https://habr.com/ru/post/1764949/


All Articles