Category Archives: MySQL

Syntax of Create temporary table in MySQL

Example of Create Temporary table in MySQL

Temporary table is useful to store temporary data in MySQL.
It will destroyed automatic when session ends. You can drop it manually also.

Create Temporary table in MySQL

CREATE TEMPORARY TABLE table_temp
(
id INT NOT NULL AUTO_INCREMENT,
title VARCHAR(100),
PRIMARY KEY ( id )
);

Create Temporary table from select query

CREATE TEMPORARY TABLE table_temp 
SELECT ColumnName1,ColumnName2,... FROM table1;

CREATE TEMPORARY TABLE IF NOT EXISTS table_temp 
SELECT ColumnName1,ColumnName2,... FROM table1;

Drop temporary table in MySQL

DROP TEMPORARY TABLE table_temp;

DROP TEMPORARY TABLE IF EXISTS table_temp;