views:

41

answers:

2

I have 3 tables (A,B,C) and I need quite often to query the result of

A inner join B
union
A inner join C

I'm just thinking which way is going to be faster:

  • to write in each query the whole thing from scratch

  • to create a view and use it in queries

+1  A: 

If the view contains no aggregations, then using the view will be exactly the same as using the raw SQL. No aggregations means that a where clause can be applied 'internally' to a view where the optimiser deems optimal (based on statistics). (I think this is often referred to as 'pushing' the where clause inside a view)

Mitch Wheat
+2  A: 

A view in general is nothing else but a stored version of the SQL, in that case no. However you might get some benefit by using indexed view, especially with aggregations....having said that..indexed views have a ton of restrictions...for one union is not allowed

SQLMenace
And if you're not running Enterprise edition, be sure to use the NOEXPAND hint with any indexed views to gain the benefit.
Joe Stefanelli