Created
August 1, 2025 18:41
-
-
Save MarkPryceMaherMSFT/4dcbeeeb83a22f7716dde98ad0b198c1 to your computer and use it in GitHub Desktop.
Revisions
-
MarkPryceMaherMSFT created this gist
Aug 1, 2025 .There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,12 @@ /* This is very rough, it doesn't work for ints/bits/etc only varchars This does not work if there are schema bound views */ select 'alter table ' + s.name + '.' + object_name(c.object_id) + ' ALTER COLUMN ' + c.name + ' ' + ttt.name + '(' + convert(varchar,c.max_length) + ');', c.max_length , c.*, tt.*, s.* from sys.columns c inner join sys.tables tt on tt.object_id = c.object_id inner join sys.schemas s on s.schema_id = tt.schema_id inner join sys.types ttt on ttt.system_type_id = ttt.user_type_id and c.system_type_id= ttt.system_type_id where c.user_type_id != c.system_type_id