Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
srouse
Starting Member
7 Posts |
Posted - 2010-02-17 : 16:11:51
|
| Is it bad practice to have a view select from another view?I am migrating to SQL Server and came across a view that selects from another view. Doesn't seem like a good idea to me, but I'd like some other opinions. I'd rather not fix it now.ThanksScott |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2010-02-18 : 01:05:05
|
| is it an indexed view?------------------------------------------------------------------------------------------------------SQL Server MVPhttp://visakhm.blogspot.com/ |
 |
|
|
denis_the_thief
Aged Yak Warrior
596 Posts |
Posted - 2010-02-18 : 11:04:09
|
| This is a very interesting one. Application Developers probably come up with this because it is the same mentality to programming: if a function can use another function that uses another function, why can't a view use another view that uses another view?First we have have to understand views (and I am assuming we are talking about 'regular' views rather than indexed views). SQL server creates one execution plan per QUERY and a View on it's own is not a query until you actually use it in a select statement. When you execute a query that contains views, SQL server will replace the view with the query behind it to come up with one query and then make an execution plan based on that query (unless an execution plan already exists for that query). So if you compare a query without views and the identical query with views, you will get the exact same results, exact same execution plan and exact same execution time.The problems arise when someone new comes along and then uses that view comprised of several views, each one of which is comprised of several more views. The person person thinks there are writing a very simple query but in actual fact, it is a very long, complicated query that runs as slow as a turtle. |
 |
|
|
|
|
|