Skip to content

Instantly share code, notes, and snippets.

@timgaunt
Created May 20, 2012 10:19
Show Gist options
  • Save timgaunt/2757576 to your computer and use it in GitHub Desktop.
Save timgaunt/2757576 to your computer and use it in GitHub Desktop.
Check the maximum length of a column
DECLARE @sql VARCHAR(max)
SELECT @sql = ''
SELECT
@sql = @sql + 'select ''' + table_name + ''',''' + column_name + ''',max(len([' + column_name + '])) from [' + table_name + '] union all '
FROM
information_schema.columns
SET @sql = left(@sql, len(@sql) - 9)
EXEC (@sql)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment