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:

CREATE TEMPORARY TABLE temp_employees
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)
values
 (201,'Alok Sharma','House No:30 New Delhi');

Leave a Reply