Skip to content
Advertisement

Persistent temp tables in SQL?

Is it possible to have a ‘persistent’ temp table in MS-SQL? What I mean is that I currently have a background task which generates a global temp table, which is used by a variety of other tasks (which is why I made it global). Unfortunately if the table becomes unused, it gets deleted by SQL automatically – this is gracefully handled by my system, since it just queues it up to be rebuilt again, but ideally I would like it just to be built once a day. So, ideally I could just set something like set some timeout parameter, like “If nothing touches this for 1 hour, then delete”.

I really don’t want it in my existing DB because it will cause loads more headaches related to managing the DB (fragmentation, log growth, etc), since it’s effectively rollup data, only useful for a 24 hour period, and takes up more than one gigabyte of HD space.

Worst case my plan is to create another DB on the same drive as tempdb, call it something like PseudoTempDB, and just handle the dropping myself.

Any insights would be greatly appreciated!

Advertisement

Answer

I would go with your plan B, “create another DB on the same drive as tempdb, call it something like PseudoTempDB, and just handle the dropping myself.”

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement