Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get size of column in mysql table

Tags:

sql

mysql

I'm trying to find out the exact size of one column within a table. PHPMyAdmin doesn't show size of columns, only the tables.

Any way I can get the size of the column?

Thankyou

like image 455
user1446650 Avatar asked Feb 14 '14 06:02

user1446650


People also ask

How do I find the size of a column in MySQL?

This can be accomplished easily with the following query: SELECT TABLE_SCHEMA AS `Database`, TABLE_NAME AS `Table`, ROUND((DATA_LENGTH + INDEX_LENGTH) / 1024 / 1024) AS `Size (MB)` FROM information_schema.

How do I find the size of a column?

Suppose we square column, so area of square =a2, hence a2 = 54925mm2, a=√54925mm2=234mm, width and depth of column =234mm×234mm, taking in round figure=230mm×300mm(9″×12″) for rectangular column.

How can I get column details of a table in MySQL?

You can get the MySQL table columns data type with the help of “information_schema. columns”. SELECT DATA_TYPE from INFORMATION_SCHEMA. COLUMNS where table_schema = 'yourDatabaseName' and table_name = 'yourTableName'.

How do I find the maximum size of a column in MySQL?

I would recommend that you consider using CHAR_LENGTH() instead of LENGTH(). CHAR_LENGTH() returns the length of a string in characters. LENGTH() returns its length in bytes. For multi-byte character sets these values can be different, and you are probably concerned with character length, not byte length.


2 Answers

If you want to find out the size of column=COLUMN_NAME from table=TABLE_NAME, you can always run a query like this:

SELECT sum(char_length(COLUMN_NAME)) 
FROM TABLE_NAME;

Size returned is in bytes. If you want it in kb, you could just divide it by 1024, like so:

SELECT sum(char_length(COLUMN_NAME))/1024 
FROM TABLE_NAME;
like image 54
tim berspine Avatar answered Oct 11 '22 17:10

tim berspine


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

INFORMATION_SCHEMA.COLUMNS

If you wanna Whole Table size then use this

SELECT table_name                                                 AS "Tables", 
       Round(( ( data_length + index_length ) / 1024 / 1024 ), 2) "Size in MB" 
FROM   information_schema.tables 
WHERE  table_schema = "$db_name" 
ORDER  BY ( data_length + index_length ) DESC; 

Edit

SELECT column_name, 
       character_maximum_length 
FROM   information_schema.columns 
WHERE  table_schema = 'websi_db1' 
       AND table_name = 'thread' 
       AND column_name = 'title' 

Source

like image 23
Vignesh Kumar A Avatar answered Oct 11 '22 15:10

Vignesh Kumar A