-
-
Save ciju/4f99669cfee0a9ada087 to your computer and use it in GitHub Desktop.
gives a summary of your mysql database tables
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- ref: http://stackoverflow.com/questions/7737970/procedure-to-loop-through-comma-separated-string-is-not-working | |
-- ref: http://www.java2s.com/Code/SQL/Procedure-Function/EXECUTEdynamicSQLcommand.htm | |
delimiter $$ | |
drop procedure if exists execsql$$ | |
create procedure execsql(q varchar(1000)) | |
begin | |
set @q = q; | |
prepare stmt from @q; | |
execute stmt; | |
deallocate prepare stmt; | |
end$$ | |
drop procedure if exists showtbl$$ | |
create procedure showtbl(tbl varchar(100)) | |
begin | |
call execsql(concat("select \"", tbl, "\"")); | |
call execsql(concat("select count(*) as entries from ", tbl)); | |
call execsql(concat("select * from ", tbl, " limit 10")); | |
end$$ | |
drop procedure if exists showalltbl$$ | |
create procedure showalltbl(strids varchar(1000)) | |
begin | |
declare strlen int default 0; | |
declare substrlen int default 0; | |
declare tbl varchar(100) default ""; | |
if strids is null then | |
set strids = ''; | |
end if; | |
do_this: | |
loop | |
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; | |
end$$ | |
delimiter ; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment