0

I have a very simplistic UNION View:

ALTER VIEW [dbo].[CD_qryAllMatch]
AS

Select *
from [dbo].[CD_qryFacetsMatch]

UNION

Select *
from [dbo].[CD_qryNonFacetsMatch]

Every once in a while, I'll need to add a new field in the source table. I'll add that field to CD_qryFacetsMatch and CD_qryNonFacetsMatch. No problem. They appear fine. Then I'll run this CD_qryAllMatch UNION View, and the fields aren't there. They're in the source table and in the source Views, but they're not appearing in the UNION View.

Is there some trick to getting new fields to appear in UNION Views? I've refreshed the View folder and refreshed the database folder and they're still not appearing.

Johnny Bones
  • 8,786
  • 7
  • 52
  • 117
  • As expected, a view is unaffected when adding new columns to its underlying tables. I.e. a view is reliable in a changing schema. – jarlh May 15 '23 at 12:48
  • Correct. However, the UNION view isn't updating to include the new fields, and I need to use a UNION view for this. – Johnny Bones May 15 '23 at 12:57
  • If you add new columns to one of the underlying tables then you need to recreate the view in order for it to pick these changes up. – NickW May 15 '23 at 12:59
  • 2
    `exec sp_refreshview 'dbo.CD_qryAllMatch'` and then `exec sp_refreshsqlmodule 'AnyProcThatReferencesTheView'` – Charlieface May 15 '23 at 13:11

0 Answers0