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

SOPA and the NDAA

Hiding an ASPXGridView Delete button with HTMLRowCreated vs. CommandButtonInitialize

Why I still don't use Entity Framework for small-to-medium business applications