Skip to content
midenok edited this page Jul 18, 2014 · 3 revisions
Get column names to paste into SELECT query
select group_concat(column_name separator ', ')
from information_schema.columns
where table_schema='<SCHEMA>' and table_name='<TABLE>';
drop procedure if exists table_columns;
delimiter ;;
create procedure table_columns(_table varbinary(255))
not deterministic
reads sql data
begin
    if @nl then
        select group_concat(column_name separator ',\n') as columns
        from information_schema.columns
        where table_schema=database() and table_name=_table;
    else
        select group_concat(column_name separator ', ') as columns
        from information_schema.columns
        where table_schema=database() and table_name=_table;            
    end if;
end;;

drop procedure if exists table_columns_nl;
create procedure table_columns_nl(_table varbinary(255))
not deterministic
reads sql data
begin
    set @nl := 1;
    call table_columns(_table);
end;;

delimiter ;
Clone this wiki locally