declare @cols table (i int identity, tablename varchar(100), colname varchar(100))
insert into @cols
select TABLE_NAME, COLUMN_NAME
from information_schema.COLUMNS
where DATA_TYPE='nvarchar'
select * from @cols
declare @i int, @maxi int
select @i = 1, @maxi = MAX(i) from @cols
declare @sql nvarchar(max)
while(@i <= @maxi)
begin
select @sql = 'alter table sub_history.'+tablename+' alter column ' + colname + ' varchar(255) NULL' from @cols where i = @i
exec sp_executesql @sql
select @i = @i + 1
end
How to ALTER all tables columns in SQL Database
by
Tags: