How to get the size of a varchar[n] field in one SQL statement?

后端 未结 8 1560
自闭症患者
自闭症患者 2020-11-29 01:20

Suppose that I have a SQL table that has a varchar[1000] field called \"Remarks\".

I would like to craft a single SQL statement, which when executed, will return 100

8条回答
  •  一整个雨季
    2020-11-29 01:22

    For t-SQL I use the following query for varchar columns (shows the collation and is_null properties):

    SELECT
        s.name
        , o.name as table_name
        , c.name as column_name
        , t.name as type
        , c.max_length
        , c.collation_name
        , c.is_nullable
    FROM
        sys.columns c
        INNER JOIN sys.objects o ON (o.object_id = c.object_id)
        INNER JOIN sys.schemas s ON (s.schema_id = o.schema_id)
        INNER JOIN sys.types t ON (t.user_type_id = c.user_type_id)
    WHERE
        s.name = 'dbo'
        AND t.name IN ('varchar') -- , 'char', 'nvarchar', 'nchar')
    ORDER BY
        o.name, c.name
    

提交回复
热议问题