Retrieve the maximum length of a VARCHAR column in SQL Server

前端 未结 10 1650
时光说笑
时光说笑 2021-01-30 10:18

I want to find the longest VARCHAR in a specific column of a SQL Server table.

Here\'s an example:

ID = INT IDENTITY
DESC = VARCHAR(5000)

I         


        
10条回答
  •  清酒与你
    2021-01-30 10:29

    For sql server (SSMS)

    select MAX(LEN(ColumnName)) from table_name
    

    This will returns number of characters.

     select MAX(DATALENGTH(ColumnName)) from table_name
    

    This will returns number of bytes used/required.

    IF some one use varchar then use DATALENGTH.More details

提交回复
热议问题