Skip to content

Instantly share code, notes, and snippets.

@MarkPryceMaherMSFT
Created August 1, 2025 18:41
Show Gist options
  • Save MarkPryceMaherMSFT/4dcbeeeb83a22f7716dde98ad0b198c1 to your computer and use it in GitHub Desktop.
Save MarkPryceMaherMSFT/4dcbeeeb83a22f7716dde98ad0b198c1 to your computer and use it in GitHub Desktop.
this generates the script to alter the columns and remove the user defined data types
/*
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment