View Single Post

   
  #2 (permalink)  
Old 04-29-2008, 08:27 PM
C.R.Vegelin
 
Posts: n/a
Default Re: How to know the maximum length of a field

Hi Charles,

to get max . # characters:
SELECT MAX(CHAR_LENGTH(<fieldname>)) AS `MaxChars`;

to get max. # bytes:
SELECT MAX(LENGTH(<fieldname>)) AS `MaxBytes`;

HTH, Cor

----- Original Message -----
From: "Charles Lambach" <charles.lambach@gmail.com>
To: <mysql@lists.mysql.com>
Sent: Tuesday, April 29, 2008 1:21 PM
Subject: How to know the maximum length of a field


> Hi.
>
> I've got a table with some fields, which I created with VARCHAR(100).
>
> I want to optimize this table, and I want to modify the length of these
> fields from VARCHAR(100) to VARCHAR(maximum_length), where
> "maximum_length"
> is the length of the record with the longest field.
>
> I could create a Perl script to do it, but I wonder if there's a mySQL
> command which does it automatically.
>
> Thank you very much,
> --Charles
>



Reply With Quote