Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Created August 1, 2025 18:41
Show Gist options
  • Select an option

  • Save MarkPryceMaherMSFT/4dcbeeeb83a22f7716dde98ad0b198c1 to your computer and use it in GitHub Desktop.

Select an option

Save MarkPryceMaherMSFT/4dcbeeeb83a22f7716dde98ad0b198c1 to your computer and use it in GitHub Desktop.

Revisions

  1. MarkPryceMaherMSFT created this gist Aug 1, 2025.
    12 changes: 12 additions & 0 deletions updatecolumns.sql
    Original 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