Return to Snippet

Revision: 38400
at January 1, 2011 01:42 by gtaking


Updated Code
DECLARE id_val  int(11) ;
declare table_lnk varchar(255) ;
select `<column>` into id_val from `<table>` where `<condition>`;
#Create the new table name 
set @create_query = 'CREATE  TABLE  `?` (<column/s> )';
set table_lnk=concat(id_val,'_table');
set @create_query =replace(@create_query,'?',table_lnk);
#Prepare the create table statement 
# preparation is necessary for dynamic table name
prepare create_table_stmt from @create_query;
execute create_table_stmt ;
DEALLOCATE PREPARE create_table_stmt;

Revision: 38399
at January 1, 2011 01:42 by gtaking


Updated Code
DECLARE id_val  int(11) ;
declare table_lnk varchar(255) ;
select `<column>` into id_val from `<table>` where `<condition>`;
#Create the new table name 
set @create_query = 'CREATE  TABLE  `?` (<column/s> )';
set table_lnk=concat(id_val,'_table');
set @create_query =replace(@create_query,'?',table_lnk);
#Prepare the create table statement 
# preparation is necessary for dynamic table name
prepare create_table_stmt from @create_query;
execute create_table_stmt ;
DEALLOCATE PREPARE create_table_stmt;
END

Revision: 38398
at January 1, 2011 01:07 by gtaking


Updated Code
DECLARE id_val  int(11) ;
declare table_lnk varchar(255) ;
select `<column>` into id_val from `<table>` where `<condition>`;
#Create the new table name 
set @create_query = 'CREATE  TABLE  `?` (<column/s> )';
set @create_query =replace(@create_query,'?',table_lnk);
#Prepare the create table statement 
# preparation is necessary for dynamic table name
prepare create_table_stmt from @create_query;
execute create_table_stmt ;
DEALLOCATE PREPARE create_table_stmt;
END

Revision: 38397
at January 1, 2011 01:07 by gtaking


Initial Code
DECLARE id_val  int(11) ;
declare table_lnk varchar(255) ;
select `<column>` into id_val from `<table>` where `<condition>`;
#Create the new table name 
set @create_query = '
CREATE  TABLE  `?` (<column/s> )';
set @create_query =replace(@create_query,'?',table_lnk);
#Prepare the create table statement 
# preparation is necessary for dynamic table name
prepare create_table_stmt from @create_query;
execute create_table_stmt ;
DEALLOCATE PREPARE create_table_stmt;
END

Initial URL


Initial Description
the following code can be used to create a table with a dynamic name

Initial Title
Create a table with a dynamic name

Initial Tags
mysql, sql, table

Initial Language
MySQL