Home Forums SQL Server 2008 T-SQL (SS2K8) i need the max length value of every column in every table in a database RE: i need the max length value of every column in every table in a database

  • something like this? also, max_length only makes sense for char types, so you mean like varchar/nvarchars right?

    SELECT

    OBJECT_NAME(OBJECT_ID) AS tablename,

    name AS colName,

    TYPE_NAME(system_type_id),

    CASE

    WHEN TYPE_NAME(system_type_id) IN ('NCHAR','NVARCHAR')

    THEN max_length / 2

    ELSE max_length

    END AS MaxColLength

    FROM sys.columns

    WHERE TYPE_NAME(system_type_id) IN ('NCHAR','NVARCHAR','CHAR','VARCHAR')

    Lowell


    --help us help you! If you post a question, make sure you include a CREATE TABLE... statement and INSERT INTO... statement into that table to give the volunteers here representative data. with your description of the problem, we can provide a tested, verifiable solution to your question! asking the question the right way gets you a tested answer the fastest way possible!