TEMPORARY TABLE
TEMPORARY TABLE is a SQL statement in the DDL Statements category. A temporary table exists only for the duration of a session (or transaction). Automatically dropped on disconnect. The syntax is CREATE TEMPORARY TABLE temp_name (columns) [ENGINE=MEMORY];. It returns temporary table. A typical example: CREATE TEMPORARY TABLE temp_filtered_employees ( id INT, name VARCHAR(100), salary DECIMAL ); INSERT INTO temp_filtered_employees SELECT id, name, salary FROM employees WHERE department = 'IT'; SELECT AVG(salary) FROM temp_filtered_employees; -- Table is automatically dropped when session closes -- PostgreSQL: CREATE TEMP TABLE temp_high_earners AS SELECT * FROM employees WHERE salary > 100000; -- Global temp (##) in SQL Server: CREATE TABLE ##global_temp (id INT); -- Visible to all sessions A close relative is CREATE TABLE, which creates a new table in the database with specified columns, data types, and constraints. A close relative is ALTER TABLE, which modifies an existing table: add/drop columns, modify data types, rename, add/drop constraints.