The article contains information about the MySQL Temporary Tables used to create a temporary table in MySQL VTY system.
What is Temporary Tables in MySQL?
The Temporary Table feature in MySQL is used to create a virtual table where data is temporarily stored.
The temporary table created does not appear when the tables are listed by the list command.
The temporary table allows to use SELECT, INSERT, UPDATE, DELETE statements.
Temporary tables are deleted when the session expires, as in MySQL variables.
Create Temporary Table in MySQL
Creating a temporary table is created in a similar way to SQL table creation, with the TEMPORARY suffix in front of it.
The following statement is used to create a temporary table.
CREATE TEMPORARY TABLE my_temp_table_name (
column1 data_type restriction,
column2 data_type restriction,
column3 data_type restriction,
Temporary tables are used to store / process frequently used data.
Copy Table to Temporary Table in MySQL
Copying existing tables to temporary tables is similar to copying SQL tables. It is copied by putting the TEMPORARY prefix in front of it.
The following statement is used to copy a table.
CREATE TEMPORARY TABLE temp_table_name AS
SELECT column1, column2, ...
You can also use it in the following ways.
CREATE TEMPORARY TABLE temp_table_name LIKE current_table;
INSERT temp_table_name SELECT * FROM current_table WHERE ...;
Temporary table names can be the same as existing table names.
That is, even if there is a table named category, you can create a temporary table named category.
However, when the categories table is listed, the data in the temporary table are listed.
Also, the data added to the temporary table will be deleted when the session ends, so it may give undesired results.