Question

I've got a table that can contain a variety of different types and fields, and I've got a table definitions table that tells me which field contains which data. I need to select things from that table, so currently I build up a dynamic select statement based on what's in that table definitions table and select it all into a temp table, then work from that.

The actual amount of data I'm selecting is quite big, over 5 million records. I'm wondering if a temp table is really the best way to go around doing this.

Are there other more efficient options of doing what I need to do?

Was it helpful?

Solution

If your data is static, reports like - cache most popular queries results, preferably on Application Server. Or do multidimensional modeling (cubes). That is the really "more efficient option to do that".

Temp tables, table variables, table data types... In any case you will use your tempdb, and if you want to optimize your queries, try to optimize tempdb storage (after checking IO statistics ). You can aslo create indexes for your temp tables.

OTHER TIPS

You can use Table Variables to achieve the functionality. If you are using the same structure in multiple queries, you can go for custom defined Table data types as well.

http://technet.microsoft.com/en-us/library/ms188927.aspx

http://technet.microsoft.com/en-us/library/bb522526(v=sql.105).aspx

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top