/ Published in: MySQL
the following code can be used to create a table with a dynamic name
Expand |
Embed | Plain Text
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;
You need to login to post a comment.
