How good is your SQL Kung-Fu?

The problem with management reports is that they never run well against OLTP databases. That's because the indexing is configured for a different use. This is why some use datawarehouse solutions. For example if your RDBMS supports partioning you set up your partitions accordingly. For example by months or quarters etc. This substantially speeds up these type of queries.

Alternative strategies include creating an index specifically for the query which you can drop afterwards. There is an overhead in creating the index but overall it may be faster.
Temp tables only help in some situations. If your temp table is not signficantly smaller than your original table it may not help much. You need to experiment. But reading large tables without hitting good indexes is always going to be painful.
 
No offense to any of the guys who responded, but you'll get much better responses if you ask this on StackOverflow.com. Get answers from the experts.

Oh so stackoverflow is the only place people with expertise reside.... okay :erm: I mean lets not forget that Toxic is/was a DBA.
 
I missed that ****. Hope its not mssql
A fair number of people still swear by them... drives me nuts... they can be useful in some situations but usually there are much better ways to do things.

The CTE does seem like it might suit this type of query better than temp tables though.. It may be faster
 
Oh so stackoverflow is the only place people with expertise reside.... okay :erm: I mean lets not forget that Toxic is/was a DBA.
Was a dba and was a db Dev... so not 100% up to speed on the new **** in Sql 2012 and 2014.. but still...
 
Learnt and used CTE's today and they are really powerful.
Worth a look.

Took me a while scrolling down til someone mentioned CTE.
Seriously. CTE for this. No brainer.

No offense to any of the guys who responded, but you'll get much better responses if you ask this on StackOverflow.com. Get answers from the experts.


And yes, StackOverflow is the place to ask questions like this.

Glad CTE made it to the discussion and cursors got a WTF. Are cursors still legal?
 
Last edited:
Top
Sign up to the MyBroadband newsletter
X