I need to change all nulls in a table to 0

Please hlep do that for the data, the data is huge
sqlcuriousAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Aneesh RetnakaranDatabase AdministratorCommented:
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
0
Kyle AbrahamsSenior .Net DeveloperCommented:
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.
0
Brian CroweDatabase AdministratorCommented:
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.
0
Newly released Acronis True Image 2019

In announcing the release of the 15th Anniversary Edition of Acronis True Image 2019, the company revealed that its artificial intelligence-based anti-ransomware technology – stopped more than 200,000 ransomware attacks on 150,000 customers last year.

sqlcuriousAuthor Commented:
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
0
Aneesh RetnakaranDatabase AdministratorCommented:
Use this to build the Update query

select COLUMN_name +' = ' +'ISNULL(' +COLUMN_NAME +',0) ,' from INFORMATION_SCHEMA.COLUMNS  where table_name = ' yourTableName' and IS_NULLABLE
= 'YES'

Copy the results to a new query window , remove the last comma at the bottom,  add an update statement at the top 'update yourTableName'
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sqlcuriousAuthor Commented:
thanks
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Microsoft SQL Server

From novice to tech pro — start learning today.