Question 1: Indexing
Which of the following is the most effective way to speed up a query that frequently filters data based on a specific column?
- Adding more RAM to the database server
- Creating an index on that column
- Rewriting the query using a different SQL dialect
- Increasing the size of the database cache
- Dropping infrequently used indexes
Question 2: JOIN Optimization
When joining two large tables, what type of JOIN is generally the most efficient if you only need matching rows from both tables?
- LEFT JOIN
- RIGHT JOIN
- FULL OUTER JOIN
- INNER JOIN
- CROSS JOIN
Question 3: WHERE Clause Order
How does the order of conditions in a WHERE clause generally affect query performance?
- The order is irrelevant; the database optimizes it automatically.
- Conditions that filter out the most rows first should be placed earlier.
- Conditions that are computationally cheapest should be placed earlier.
- The order only matters for very small tables.
- Conditions involving indexed columns should always be last.
Question 4: Using EXPLAIN
Which SQL command is used to analyze the execution plan of a query without actually running it, helping identify potential bottlenecks?
- ANALYZE
- OPTIMIZE
- EXPLAIN
- DESCRIBE
- PROFILE
Question 5: Avoiding SELECT *
Why is it generally recommended to avoid using `SELECT *` in frequently used queries?
- It is more difficult to read and understand.
- It always returns incorrect results.
- It retrieves unnecessary data, increasing I/O and network traffic.
- It prevents the database from using indexes.
- It can cause the database server to crash.
Question 6: Query Hinting
What is query hinting in SQL?
- A method of writing SQL queries in a rhyming format.
- Providing instructions to the database optimizer on how to execute the query.
- Adding comments to the SQL query to explain its purpose.
- A technique for encrypting sensitive data within the database.
- A method of automatically generating SQL queries from natural language.
Question 7: Stored Procedures
How can using stored procedures improve the performance of frequently executed database operations?
- By automatically encrypting the data being processed.
- By pre-compiling the SQL code and storing it on the server.
- By bypassing the database server altogether.
- By allowing users to directly access the database tables without authentication.
- Stored procedures cannot improve performance.
Question 8: Data Types
Choosing the correct data type for your columns can impact performancWhich data type is generally most efficient for storing small whole numbers?
- VARCHAR
- TEXT
- BIGINT
- INT
- TINYINT
Question 9: Limiting Results
A dashboard displays the top 10 most recent transactions. How can you efficiently retrieve only these 10 records?
- Retrieve all transactions and filter the first 10 in the application code.
- Use the `LIMIT` clause in the SQL query.
- Increase the database server's memory to accommodate all transactions.
- Delete older transactions to reduce the result set size.
- Use a `WHERE` clause that checks for transactions within the last 10 days.
Question 10: Connection Pooling
What benefit does connection pooling provide in improving database query performance?
- It automatically backs up the database after each query.
- It reduces the overhead of establishing new connections for each query.
- It allows multiple users to access the database simultaneously without any restrictions.
- It optimizes the SQL query itself before execution.
- It automatically encrypts all data transmitted between the application and the database.