MySQL确定最长的VarChar长度 [英] MySQL Determine longest VarChar length
本文介绍了MySQL确定最长的VarChar长度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试优化数据库.为此,我需要能够确定varchar列中最长的数据条目,然后将列定义修整到刚好在其上方.
I am trying to optimize my database. In order to do so, I need to be able to determine the longest data entry in a varchar column, and then trim the column definition to just above that.
如何使用sql找出表中最长varchar条目的长度?
How can I find out, using sql, the length of the longest varchar entry in my table?
CREATE TABLE `poller_output` (
`local_data_id` mediumint(8) unsigned NOT NULL DEFAULT '0',
`rrd_name` varchar(19) NOT NULL DEFAULT '',
`time` datetime NOT NULL DEFAULT '0000-00-00 00:00:00',
`output` varchar(200) NOT NULL DEFAULT '',
PRIMARY KEY (`local_data_id`,`rrd_name`,`time`)
) ENGINE=MEMORY DEFAULT CHARSET=utf8
推荐答案
例如,如果您想知道字段output
的最大长度,则可以使用以下查询:
If you want to know the max length of the field output
, for example, you can use this query:
SELECT Max(CHAR_LENGTH(`output`)) AS Max FROM `poller_output`
这篇关于MySQL确定最长的VarChar长度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文