Forum Moderators: coopster

Message Too Old, No Replies

HOW TO set all values in a (MySQL) field to zero?

         

Ataraxia

5:38 pm on Oct 5, 2004 (gmt 0)

10+ Year Member



Sorry for such an elementary, "newbie" question on MySQL but I really don't know how to do this for sure and I don't want to screw it up:

Let's say each record in the "ABC" field of my "XYZ" table contains a different numerical value. I need to set all of the values in ABC to zero.

I'm guessing this QUERY might do it:

UPDATE XYZ SET ABC=(REPLACE (ABC, '*','0'));

Am I right? (I cannot afford to be wrong!)

Thanks!

jatar_k

5:50 pm on Oct 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



I think you could even be simpler

if every value in that column needs to be set to 0 then just

UPDATE XYZ SET ABC=0;

with no where clause it will apply the change to every row in the table

Ataraxia

6:12 pm on Oct 5, 2004 (gmt 0)

10+ Year Member



Jatar said:
> UPDATE XYZ SET ABC=0;
> with no where clause it will apply the change to
> every row in the table

You said "every row in the table". Did you actually mean "every row in the (ABC) field"?

There are other fields in the XYZ table that I do NOT want to set to zero. Will UPDATE XYZ SET ABC=0; set all all rows in all fields in the table to zero or just the ones in the ABC field?

Thanks for your help!

jatar_k

6:22 pm on Oct 5, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



>> set all all rows in all fields in the table to zero or just the ones in the ABC field?

UPDATE XYZ SET ABC=0;

let's read this in english then

update the XYZ table by setting every value in the ABC column to 0

So, only the ABC column since that is the column we have specified but it will reset every single value in that column.

Ataraxia

2:36 pm on Oct 6, 2004 (gmt 0)

10+ Year Member



This worked great! Thanks for the help!