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.
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

Popular posts from this blog

SQL 2005 SP4 and MSreplication_subscriptions

Hiding an ASPXGridView Delete button with HTMLRowCreated vs. CommandButtonInitialize

SQL Server Deadlocks - Easy Quick Start Guide