SQL Interview Prep 7: Do temp tables make your code cleaner and faster, one of the two, or none? Why?

365 Days of Daily Coding: Day 115

I have been trying to stay consistent with my morning workouts but alas, I have been very lazy to follow through my goal. Hoping that tomorrow I have the will to resume it again.

As for the question, I read few articles to understand why temp tables should be used. This would be a question suited for those that have advanced sql skill and are experienced in optimising sql queries.

Here’s the summary of my understanding after reading few articles.

Temp tables are storage tables that exists only temporarily in database. When the connection that created the temp tables is closed, it ceases to exist. Depending on the type of temp tables for instance with global temp tables, it is possible for multiple connections/sessions to call the temp tables.

In my opinion, temp tables do make the code cleaner in respect to making it easier to follow the logic and understand it. Some of the articles do suggest that using temp tables can make the processing faster as we can use temp tables to process and store complex sql queries which then can be references by other sql statements.

Leave a comment