Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get the max length allowed in column, mysql

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

like image 788
user2132046 Avatar asked Dec 03 '22 00:12

user2132046


2 Answers

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
  • SQLFiddle Demo
like image 142
John Woo Avatar answered Jan 01 '23 01:01

John Woo


The following SQL query will give the maximum column length.

SELECT max(length(column)) `max_column_length` from tab;
like image 39
Adeel Raza Azeemi Avatar answered Jan 01 '23 01:01

Adeel Raza Azeemi