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;

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.