Local vs Global Temporary Tables
CONCEPTS:SQL Temporary Tables
Question Variations
- "What is the difference between a local temporary table (`#`) and a global temporary table (`##`)?"
- "When is a local temporary table automatically dropped by the database engine?"
- "Who can see and access a global temporary table once it has been created?"
- "Compare the use of temporary tables versus table variables (`@table`)."
Why This Is Asked
This question tests depth of knowledge in SQL Server session management and tempdb usage. It’s important for writing complex stored procedures and multi-user scripts.
Key Concepts
- Scope: Who can see the table?
- Lifetime: When is the table dropped?
- Syntax: Prefix differences (
#vs##).
Question Variations
- “What is the difference between a local temporary table (
#) and a global temporary table (##)?” - “When is a local temporary table automatically dropped by the database engine?”
- “Who can see and access a global temporary table once it has been created?”
- “Compare the use of temporary tables versus table variables (
@table).”