Define a Temp Table
Define a Temp Table
A temporary table stores intermediate rows that only matter for the current session or transaction. The database removes it automatically, so it never clutters the permanent schema.
| Database | Syntax | Lifetime |
|---|---|---|
| SQL Server | #name (session-local), ##name (global, visible to all sessions) |
Dropped when the creating session ends (global: when the last session using it ends). Stored in tempdb. |
| PostgreSQL | CREATE TEMP TABLE name (...) |
Per session, optionally ON COMMIT DROP or DELETE ROWS. Invisible to other sessions. |
| MySQL / MariaDB | CREATE TEMPORARY TABLE name (...) |
Per connection. Dropped when the connection closes. |
| Oracle | CREATE GLOBAL TEMPORARY TABLE (definition is permanent, data is private) |
Rows live for the transaction or session. |
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.