select not_null = 'alter table ' + table_name + ' alter column '
+ column_name + ' ' + data_type
+ case when data_type = 'numeric' then '(' else '' end
+ case when data_type = 'numeric' then convert(varchar,numeric_precision_radix) else '' end
+ case when data_type = 'numeric' then ',' else '' end
+ case when data_type = 'numeric' then convert(varchar,numeric_scale) else '' end
+ case when data_type = 'numeric' then ')' else '' end
+ ' not null '
,default_0 = 'alter table ' + table_name
+ ' add default 0 for ' + column_name
from information_schema.columns
where data_type not like '%char%'
and data_type not like '%time%'
and data_type not like '%image%'
and data_type not like '%binary%'
and column_default is null
and columnproperty(object_id(table_name), column_name,'IsIdentity') = 0
order by data_type
|