Create a table in a procedure : Create Table « Procedure Function « MySQL Tutorial






mysql> delimiter $$
mysql>
mysql>
mysql> CREATE PROCEDURE myProc()
    -> BEGIN
    ->      DECLARE i INT DEFAULT 1;
    ->
    ->      SET autocommit=0;
    ->
    ->      DROP TABLE IF EXISTS test_table ;
    ->      CREATE TABLE test_table (
    ->           id        INT PRIMARY KEY,
    ->            some_data VARCHAR(30))
    ->      ENGINE=innodb;
    ->
    -> END$$
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> delimiter ;
mysql> call myProc();
Query OK, 0 rows affected, 1 warning (0.08 sec)

mysql> drop procedure myProc;
Query OK, 0 rows affected (0.00 sec)

mysql> desc test_table;
+-----------+-------------+------+-----+---------+-------+
| Field     | Type        | Null | Key | Default | Extra |
+-----------+-------------+------+-----+---------+-------+
| id        | int(11)     | NO   | PRI |         |       |
| some_data | varchar(30) | YES  |     | NULL    |       |
+-----------+-------------+------+-----+---------+-------+
2 rows in set (0.00 sec)

mysql> drop table test_table;
Query OK, 0 rows affected (0.03 sec)

mysql>








11.40.Create Table
11.40.1.Create a table in a procedure
11.40.2.CREATE TEMPORARY TABLE in a procedure
11.40.3.Create a TEMPORARY table and save data into it in a procedure