Create a gist now

Instantly share code, notes, and snippets.

@ciju /summary.sql Secret
Created Sep 7, 2013

What would you like to do?
gives a summary of your mysql database tables
-- ref:
-- ref:
delimiter $$
drop procedure if exists execsql$$
create procedure execsql(q varchar(1000))
set @q = q;
prepare stmt from @q;
execute stmt;
deallocate prepare stmt;
drop procedure if exists showtbl$$
create procedure showtbl(tbl varchar(100))
call execsql(concat("select \"", tbl, "\""));
call execsql(concat("select count(*) as entries from ", tbl));
call execsql(concat("select * from ", tbl, " limit 10"));
drop procedure if exists showalltbl$$
create procedure showalltbl(strids varchar(1000))
declare strlen int default 0;
declare substrlen int default 0;
declare tbl varchar(100) default "";
if strids is null then
set strids = '';
end if;
set strlen = char_length(strids);
set tbl = substring_index(strids, ',', 1);
call showtbl(tbl);
set substrlen = char_length(tbl)+2;
set strids = mid(strids, substrlen, strlen);
if strids = null then
leave do_this;
end if;
if strids = '' then
leave do_this;
end if;
end loop do_this;
delimiter ;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment