Question №27
Remaining:
What is a temporary table in SQL?
Sample Answer
Show Answer by Default
A temporary table is a table that exists only for the duration of the current session or connection and is automatically deleted when the session ends or the connection is closed.
Creating a temporary table
MySQL 8.1CREATE TEMPORARY TABLE TempTable ( id INT, name VARCHAR(100) );
Using a temporary table
MySQL 8.1-- inserting data into the temporary table INSERT INTO #TempTable (id, name) VALUES (1, 'Иван'), (2, 'Петр'); -- selecting data from the temporary table SELECT * FROM #TempTable; -- the temporary table will be automatically deleted after the session ends
Applications of temporary tables
- Storing intermediate results in complex queries.
- Handling large datasets in batch operations.
- Avoiding conflicts when multiple users are working simultaneously.