Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 SQL Server 2005 Forums
 Transact-SQL (2005)
 need to create list of columns w/ max data length

Author  Topic 

stonebreaker
Yak Posting Veteran

92 Posts

Posted - 2007-09-12 : 16:00:33
I'm trying to create a stored proc that will give me a list of columns within a table, and the maximum data length in each column. I want to find the max data length so I can reduce the column size. So far I have been able to get the list of columns along with the maximum column size:

declare
@tablename varchar(50)
,@columnname varchar(50)
set @tablename =
select t.[name] as table_name
,c.[object_id]
,c.[name] as column_name
,c.max_length as column_length
from sys.tables t inner join sys.columns c
on t.object_id = c.object_id
where t.name like @tablename

Any help getting the max(len(<column>)) would be greatly appreciated.

jen
Master Smack Fu Yak Hacker

4110 Posts

Posted - 2007-09-12 : 16:04:17
check out..

information_schema.columns... everything is there

--------------------
keeping it simple...
Go to Top of Page

Lamprey
Master Smack Fu Yak Hacker

4614 Posts

Posted - 2007-09-12 : 16:09:07
There are many ways to get at that information. But, here is a link to some stuff that will do that: [url]http://www.msftdwtoolkit.com/ToolsandUtilities/ToolandUtilities.htm[/url]. Spefically, look for Chapter 2: Data profiling reports. It's a zip file with a couple stored procedures you can use / modify that will return that informaion.
Go to Top of Page

stonebreaker
Yak Posting Veteran

92 Posts

Posted - 2007-09-13 : 08:57:28
quote:
Originally posted by Lamprey

There are many ways to get at that information. But, here is a link to some stuff that will do that: [url]http://www.msftdwtoolkit.com/ToolsandUtilities/ToolandUtilities.htm[/url]. Spefically, look for Chapter 2: Data profiling reports. It's a zip file with a couple stored procedures you can use / modify that will return that informaion.


Thank you, that did the trick. You learn something new every day - I never thought of putting the whole sql statement into a variable and executing it that way.
Go to Top of Page
   

- Advertisement -