mysql - Show table name where a value is present -


is possible show name of table in db specific value present. have different tables , want show table names contains specific value in of fields.

this return lots of empty result sets, non-empty ones correspond table/column combinations fit search. works text, , detects columns contain value (as opposed full column match.)

delimiter |  drop procedure if exists `searchalltables`| create procedure `searchalltables` (     in _search varchar(256)     ) language sql deterministic sql security definer begin     -- declare stuff     declare _tablename varchar(64);     declare _columnname varchar(64);     declare _done tinyint(1) default 0;      -- examine every string column in database     declare _columncursor cursor         select table_name, column_name             information_schema.columns         table_schema = database()         , (data_type '%char%'              or data_type 'text');     declare continue handler not found         set _done = 1;      open _columncursor;     loop1: loop             -- next table/column combination         fetch _columncursor _tablename,_columnname;         if _done = 1             close _columncursor;             leave loop1;         end if;              -- query current column see if holds value         set @query = concat(             "select '",_tablename,"' tablename, '",                       _columnname,"' columnname              ",_tablename,"              ",_columnname," concat('%',?,'%')              group 1;"         );         set @search = _search;         prepare _stmt @query;         execute _stmt using @search;         deallocate prepare _stmt;     end loop loop1; end|  delimiter ; 

oh, yeah, , it's ugly... maybe it'll you, though!


Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -