SQL Temporary Table: Create & Import Guide

To create a temporary table and import data, you can follow these steps:

  1. Create a temporary table using the CREATE TABLE statement, where you can specify the table’s structure.
CREATE TEMPORARY TABLE temp_table (
    id INT,
    name VARCHAR(50),
    age INT
);
  1. Import data: Use the INSERT INTO statement to insert data into a temporary table, for example:
INSERT INTO temp_table (id, name, age) VALUES (1, 'Alice', 25);
INSERT INTO temp_table (id, name, age) VALUES (2, 'Bob', 30);
INSERT INTO temp_table (id, name, age) VALUES (3, 'Charlie', 35);
  1. Using temporary tables: You can query and manipulate temporary tables within the current session, for example:
SELECT * FROM temp_table;
  1. Delete temporary table: Temporary tables will be automatically removed at the end of a session, but you can also manually delete them using the DROP TABLE statement, for example:
DROP TEMPORARY TABLE temp_table;

By following the above steps, you can create a temporary table, import data, and then use this temporary table for querying and operations within the current session.

bannerAds