Link to home
Start Free TrialLog in
Avatar of sqlcurious
sqlcuriousFlag for United States of America

asked on

I need to change all nulls in a table to 0

Please hlep do that for the data, the data is huge
Avatar of Aneesh
Aneesh
Flag of Canada image

update tableA
Set columnC = 0
where columnC is null

This may take a long time and create a huge log depending on how much data you have, so please run this during off peak hours
If you wanted to run this in batches you could do something like:

update tableA
Set columnC = 0
where columnC is null
and id between 1 and 50000

then you could rerun:

update tableA
Set columnC = 0
where columnC is null and id between 50001 and 100000


it will allow everything to process but not tie up the server forever.  Increase or decrease the range as necessary.

ID is the primary key of your table, usually an int.
UPDATE myTable
SET myColumn1 = ISNULL(myColumn1, 0),
   myColumn2 = ISNULL(myColumn2, 0)
   ...


I don't know of any magic bullet to handle "huge" data other than doing it in batches as ged recommends or just doing it during an off time when it won't affect the system too adversely.
Avatar of sqlcurious

ASKER

I have about 60 columns for which I have to do this :(, I am trying your approaches but messed it up mid way :(, please suggest an alternative way
ASKER CERTIFIED SOLUTION
Avatar of Aneesh
Aneesh
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thanks