neoo neoo - 1 year ago 47
SQL Question

Script to change Null values for all columns in table

Hi I am looking for SQL Server script or query which makes
Null values to user defined default values for all columns in a table.

I know we can do column by column but my table contains 300 columns.

Thanks in advance..

Answer Source

I have re-written my query to set the values to 0.

SELECT 'UPDATE [Your Table] SET ' 
        + + ' = COALESCE(' 
        + + ',''0'')'  FROM sys.columns AS c
JOIN sys.tables AS t ON t.object_id = c.object_id
WHERE = '[Your table]'