February 13, 2024 at 9:42 am
Dears,
Hope this message finds you well
I would like to ask if there is any difference from a performance perspective between joining to make a View from two base tables, or if its better to create from each base table a like to like view and after, create the view which is a join of both viewes
like:
Thanks a lot,
Pedro
February 13, 2024 at 2:10 pm
In general, it's better to avoid nesting views -- so for your case, make the view you want from the two base tables.
Why?
February 13, 2024 at 2:11 pm
Thanks a lot
February 14, 2024 at 1:42 pm
Just remember, a view is nothing but a query (materialized views are a different discussion). As a query, is it better to write a specific query for a specific need, or, is it better to combine two or more generic queries, making for a very large query indeed? Simple answer is that a specific query is better.
Views are a handy way of obscuring structures or providing masking for data or other stuff like that. They are 100% NOT meant to be objects like in code and therefore used as building blocks for other queries. This type of anti-pattern causes all sorts of headaches.
"The credit belongs to the man who is actually in the arena, whose face is marred by dust and sweat and blood"
- Theodore Roosevelt
Author of:
SQL Server Execution Plans
SQL Server Query Performance Tuning
February 14, 2024 at 2:05 pm
Just adding my 2cents;
One could easily write a book on the subject, luckily, Grant already has so check out his excellent work!
Viewing 5 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply
This website stores cookies on your computer.
These cookies are used to improve your website experience and provide more personalized services to you, both on this website and through other media.
To find out more about the cookies we use, see our Privacy Policy