Alter several columns datatypes at once in SQL Server
Here's a script to generate alter column statements for all the audit fields in your database. In this case we are wanting to convert all the integer columns to varchar.
Quick review of Alter Table Alter Column available at SQL Server Planet:
http://sqlserverplanet.com/ddl/alter-table-alter-column
select 'alter table ' + TABLE_NAME + ' alter column ' + COLUMN_NAME + ' varchar(50) null;'
from INFORMATION_SCHEMA.COLUMNS
where COLUMN_NAME in ('InsertedBy', 'UpdatedBy')
and DATA_TYPE = 'int'
Quick review of Alter Table Alter Column available at SQL Server Planet:
http://sqlserverplanet.com/ddl/alter-table-alter-column
Comments
Post a Comment