> I have a view (vwParent) that inner joins with another view
> (vwChild). If the underlying vwChild view is modified, the vwParent
> still returns the old columns it originally returned. Only rerunning
> the vwParent view corrects the issue.
> I have sample sql below that clearly illustrates the issue.
> Hopefully someone can provide me guidance on what to do here. The
> sample sql illustrates the problem, but it is actually a real world
> scenario (problem). During application runtime the vwChild view
> changes frequently, the vwParent is the main view that returns all the
> data, and the child.* syntax is leveraged to return all the columns
> contained by the vwChild view.
> a) Is there an easy way around this problem?
> b) How can I rerun the vwParent view without having to copy/paste the
> view into a stored proc that executes a string dynamically? Is there
> a way to somehow use sp_helptext to get the view's string into a
> variable that can then be used by sp_execute? Or is there a way to
> make a view refresh itself without going through a bunch of convoluted
> steps?
> ============================
> /* COPY/PASTE SAMPLE SQL TO ISQL TO SEE THE ISSUE */
> create table parent (id int, x int, y int)
> create table child (id int, a int, b int, c int)
> insert into parent (id, x, y) values (100, 1, 2)
> insert into child (id, a, b, c) values (100, 4, 5, 6)
> go
> create view vwChild
> as
> select id, a, b from child
> go
> create view vwParent
> as
> select x, y, child.*
> from parent parent
> inner join vwChild child on child.id = parent.id
> go
> -- returns colummns x, y, child.id, child.a, child.b
> select * from vwParent
> go
> alter view vwChild
> as
> select id, a, b, c from child
> go
> /*
> Even though vwChild has been modified
> vwParent still returns colummns x, y, child.id, child.a, child.b!
> */
> select * from vwParent
> go
> /*
> Rerun the vwParent view even though it hasn't changed.
> */
> alter view vwParent
> as
> select x, y, child.*
> from parent parent
> inner join vwChild child on child.id = parent.id
> go
> /*
> Rerunning the vwParent view sql now makes it return
> colummns x, y, child.id, child.a, child.b, and child.c
> */
> select * from vwParent
> go
> drop view vwChild
> drop view vwParent
> drop table parent
> drop table child