Explore fundamental concepts of temporary tables and in-memory databases, including how they are created, used, and managed. This quiz helps reinforce your understanding of temporary data storage techniques and best practices for efficient database operations.
Which statement correctly creates a temporary table for storing user session data during a transaction?
Explanation: The correct syntax uses 'CREATE TEMPORARY TABLE' to define a temporary table. 'CREATE SESSION TABLE' is incorrect as there is no such keyword in standard SQL. 'MAKE TABLE TEMP' contains a syntax error and is not valid SQL. 'CREATE TABLE session_data TEMPORARY' places 'TEMPORARY' in the wrong position, so only the first option is accurate.
What is the default scope of a temporary table created within a database session?
Explanation: Temporary tables by default exist only within the session they are created in; other sessions cannot access them. They are not accessible by all database sessions or stored permanently. Automatic backup to disk is not a default feature for temporary tables, as they are designed for short-term use.
After a session ends, what happens to the data stored in a temporary table called temp_sales?
Explanation: Once a session ends, both the temporary table and its data are automatically dropped to avoid clutter. Temporary tables are specifically designed for this transient existence. The data does not remain after the session, nor are only the indexes removed. Temporary tables are not transformed into permanent tables.
Which scenario best demonstrates why an in-memory database would be chosen?
Explanation: In-memory databases excel in scenarios requiring fast access and frequent updates because data resides entirely in RAM. Archival storage and backup requirements favor traditional disk-based databases. Managing distributed file archives is also outside the typical use case for in-memory databases.
How are the names of temporary tables typically handled to avoid conflicts with permanent tables?
Explanation: Temporary tables are scoped to the session, so name conflicts with permanent tables are avoided even if they share the same name. There is no mandatory '_tmp' or 'mem_' prefix required by syntax. Temporary tables are not visible to all users by default.
What is a common limitation of in-memory databases regarding data persistence?
Explanation: A key limitation is that in-memory databases risk losing all data on a power failure unless periodic saving to disk is performed. They do not automatically back up data to external storage or provide long-term archiving by default. Also, they support storing various data types, not just textual data.
If a user creates a temporary table named temp_orders, how can it be referenced in subsequent SQL queries within the same session?
Explanation: Once created, a temporary table is queried just like a permanent table by name in the FROM clause, within the same session. There is no need for a 'TEMP' keyword or any symbol prefix in the query, and it's not true that only permanent tables can be referenced this way.
Which is a primary advantage of using an in-memory database for an online multiplayer game's leaderboard?
Explanation: In-memory databases provide very fast access times, making them ideal for real-time applications like leaderboards. However, security, data permanence, and archival capacity are not automatic advantages of in-memory solutions.
Which statement correctly removes a temporary table named temp_projects from the current session before it ends?
Explanation: The standard statement to remove a temporary table, just like a permanent one, is 'DROP TABLE'. There are no official SQL commands 'DELETE TEMPORARY TABLE', 'REMOVE TABLE ... TEMP', or 'DROP SESSION_TABLE'.
Which situation is most appropriate for using a temporary table in a database application?
Explanation: Temporary tables are ideal for short-lived, intermediate storage, such as holding data during multi-step report processing. Permanent storage needs like configuration settings, historical data, or user passwords should not use temporary tables as they are dropped at the session's end.