1

I have this stored procedure in which i create new tables with the table_name being a variable. but though

select table_name;

returns variable value

create table table_name(some_columns);

creates a table with name table_name and not the value.

2
  • You need to use a prepared statement. Commented Jun 26, 2014 at 5:32
  • 1
    Weird is that this posting is marked duplicate by you only after you answered it. Commented Jun 26, 2014 at 6:54

1 Answer 1

2

You need to execute a prepared statement:

SET @sql = CONCAT('CREATE TABLE ', table_name, ' (some_columns);';
PREPARE stmt FROM @sql;
EXECUTE stmt;
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you. Btw the ';' inside is redundant.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.