4

i need to know how to get the max size of an specific column in mysql, the table is

turno :

CREATE TABLE `turno` (  
`idTurno` tinyint(4) NOT NULL,  
`nombreTurno` varchar(20) COLLATE utf8_spanish2_ci NOT NULL,  
`horaInicio` tinyint(4) NOT NULL,  
`horafin` tinyint(4) NOT NULL,  
`valorTurno` int(11) NOT NULL,  
PRIMARY KEY (`idTurno`)) 
ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_spanish2_ci

the column :

`nombreTurno` varchar(20) COLLATE utf8_spanish2_ci NOT NULL

i should get :

20

im getting:

NULL

the query :

SELECT MAX( LENGTH( nombreTurno ) ) AS maxl
FROM turno

hope you can help me, thank you

John Woo
  • 258,903
  • 69
  • 498
  • 492
user2132046
  • 95
  • 1
  • 2
  • 7

2 Answers2

19
select COLUMN_NAME, CHARACTER_MAXIMUM_LENGTH 
from information_schema.columns
where table_schema = DATABASE() AND   -- name of your database
      table_name = 'turno' AND        -- name of your table
      COLUMN_NAME = 'nombreTurno'     -- name of the column
John Woo
  • 258,903
  • 69
  • 498
  • 492
2

The following SQL query will give the maximum column length.

SELECT max(length(column)) `max_column_length` from tab;
StupidWolf
  • 45,075
  • 17
  • 40
  • 72
  • This only provides the maximum length of the longest record saved, not actually the maximum length the column is set to be capable of in the table setup. – Talk Nerdy To Me Oct 21 '21 at 21:34