I have to add a column, a field to multiple views in SQL Server. This is an example of a view that I'm using, where tbxxx
stay for a table and vwxxx
for a view:
ALTER VIEW [dbo].[vwFornitori_Search]
AS
SELECT IDitem,
IDana,
codice,
ragione_sociale,
c.valore AS colore
FROM tbAnagrafiche
LEFT JOIN tbColori c ON tbAnagrafiche.colore = c.IDcolore
WHERE IDitem = 'FOR'
AND ISNULL(eliminato, 0) = 0
AND ISNULL(obsoleto, 0) = 0
GO
I have to add to all my views another field, another column, that is always the principal table's primary key! The modified view will be:
ALTER VIEW [dbo].[vwFornitori_Search]
AS
SELECT IDitem,
IDana,
codice,
ragione_sociale,
c.valore AS colore,
IDana AS ID
FROM tbAnagrafiche
LEFT JOIN tbColori c ON tbAnagrafiche.colore = c.IDcolore
WHERE IDitem = 'FOR'
AND ISNULL(eliminato, 0) = 0
AND ISNULL(obsoleto, 0) = 0
GO
Usually the primary key has always the same name, like IDana
. There's a way to do that with a single script to a list of views ?