Posts

Showing posts from June, 2016

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