Create a temporary table in MariaDB or MySQL

Syntax of creating a temporary table in MariaDB or MySQL

Create Temporary Table

Create temporary table is simple just place temporary while using create table command in MySQL or MariaDB:

create temporary table temp_employees
id int Primary key,
emp_name varchar(500),
emp_address varchar(500),

Create a temporary table from the existing table:

SELECT * FROM employee where 1 = 0;

Note: Temporary table is used at the session level. Once the session closed the temporary table also dropped.

Drop the temporary table:

Drop temporary table temp_employees

Insert statement with temporary table like a base table:

insert into temp_employees(id, emp_name, emp_address)
 (201,'Alok Sharma','House No:30 New Delhi');

Leave a Reply

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

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

Twitter picture

You are commenting using your Twitter 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.