Create table variable in MySQL

They don’t exist in MySQL do they? Just use a temp table:

CREATE PROCEDURE my_proc () BEGIN 

CREATE TEMPORARY TABLE TempTable (myid int, myfield varchar(100)); 
INSERT INTO TempTable SELECT tblid, tblfield FROM Table1; 

/* Do some more stuff .... */

From MySQL here

“You can use the TEMPORARY keyword
when creating a table. A TEMPORARY
table is visible only to the current
connection, and is dropped
automatically when the connection is
closed. This means that two different
connections can use the same temporary
table name without conflicting with
each other or with an existing
non-TEMPORARY table of the same name.
(The existing table is hidden until
the temporary table is dropped.)”

Leave a Comment