In the SQL standard, LOCAL is a scope modifier that limits the lifetime and visibility of the object or setting it qualifies to the current SQL-session or current transaction. The most frequent appearance is in temporary table definitions (CREATE LOCAL TEMPORARY TABLE or DECLARE LOCAL TEMPORARY TABLE). Such a table is instantiated only for the connecting session, is invisible to other sessions, and is automatically dropped at session end (or optionally at COMMIT, depending on the ON COMMIT clause).Some dialects, notably PostgreSQL, also allow LOCAL in SET statements (SET LOCAL parameter = value) to change configuration parameters only for the running transaction. Once the transaction ends, the parameter reverts to its previous value.Key points:- LOCAL implies session-local or transaction-local scope.- Used mainly with temporary tables, but also with parameter changes.- Contrasts with GLOBAL (shared scope) or a plain setting that lasts for the whole session.- Lifetime ends automatically, so no explicit DROP is required.- Behavior can vary slightly by dialect: verify exact support and syntax.
GLOBAL, TEMPORARY, CREATE TABLE, SET, ON COMMIT, SESSION, TRANSACTION
SQL:1999
LOCAL restricts the temporary table to the creating session, ensuring other sessions cannot see or modify it.
It depends on the ON COMMIT clause. ON COMMIT PRESERVE ROWS keeps the data; ON COMMIT DELETE ROWS truncates it; ON COMMIT DROP removes the table.
Yes. Use DROP TABLE table_name; inside the session if you need to reclaim resources earlier.
No. SET LOCAL changes the parameter only for the current transaction. Once the transaction ends, the previous setting is restored.