Table info

from the Artful MySQL Tips List


Typing select ... from information_schema ... where ... over and over is cumbersome, and many MySQL interfaces don't have vertical row display formats, so run this over your system or utilities or whatever db where you keep generally useful MySQL widgets...
delimiter ;
drop procedure if exists tblinf;
delimiter go
create procedure system.tblinf( pdb varchar(64), ptbl varchar(64) )
begin
  select '   table_schema', table_schema
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '     table_name', table_name
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '     table_type', table_type
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '         engine', engine
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '        version', version
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '     row_format', row_format
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '     table_rows', table_rows
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select ' avg_row_length', avg_row_length
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '    data_length', data_length
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select 'max_data_length', max_data_length
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '   index_length', index_length
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '      data_free', data_free
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select ' auto_increment', `auto_increment`
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '    create_time', create_time
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '    update_time', update_time
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '     check_time', check_time
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select 'table_collation', table_collation
  from information_schema.tables where table_schema=pdb and table_name=ptbl
  union
  select '       total MB', round( (data_length + index_length)/1024/1024, 3 )
  from information_schema.tables where table_schema=pdb and table_name=ptbl;
end;
go
delimiter ;

Last updated 4 Apr 2024


Return to the Artful MySQL Tips page