Retrieve the maximum length of a VARCHAR column in SQL Server

前端 未结 10 1656
时光说笑
时光说笑 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:45

    Use the built-in functions for length and max on the description column:

    SELECT MAX(LEN(DESC)) FROM table_name;
    

    Note that if your table is very large, there can be performance issues.

提交回复
热议问题