Created
November 2, 2012 10:04
-
-
Save timgaunt/3999899 to your computer and use it in GitHub Desktop.
List the length of every field in the table
This file contains 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 characters
DECLARE @table SYSNAME, @field SYSNAME | |
set @table = '## Your table name ##' | |
CREATE TABLE #Temp (TableName SYSNAME, ColumnName SYSNAME, MaxLength INT) | |
DECLARE a_cursor CURSOR STATIC | |
FOR | |
SELECT name FROM syscolumns c WHERE id = object_id(@table) | |
OPEN a_cursor | |
FETCH NEXT FROM a_cursor INTO @field | |
WHILE @@FETCH_STATUS = 0 | |
BEGIN | |
INSERT INTO #temp | |
EXEC ('select ''' + @table + ''', ''' + @field + ''', max(len(' + @field + ')) from ' + @table ) | |
FETCH NEXT FROM a_cursor INTO @field | |
END | |
CLOSE a_cursor | |
DEALLOCATE a_cursor | |
SELECT * FROM #Temp | |
DROP TABLE #Temp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment