Is there a more efficient way of selecting data from a dynamic table than using a temp table?

StackOverflow https://stackoverflow.com/questions/21845732

문제

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?

도움이 되었습니까?

해결책

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.

다른 팁

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

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top