Question : Alter column , entire table

Please rectify where clause of the following code to eliminate identity column.
Code Snippet:
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
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
order by data_type
Open in New Window Select All

Answer : Alter column , entire table

below script remove listing column with identity


1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
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
Open in New Window Select All
Random Solutions  
 
programming4us programming4us