How to add a new column to an existing view in SQL Server 2014 using Alter

I created a view based on a different view and table. I want to add a new varchar type column. I liked the below, but getting a syntax error? I am new to SQL, so I could not understand

ALTER VIEW [dbo].[MyView]
ADD New_Col varchar(10) null 
GO
+4
source share
2 answers

you need to write the whole view again and just add or omit what you want to change

for example, your view now:

create view myView as
  select field1
  from table1

and now you want to add the field you are writing:

alter view myView as
  select field1,
         New_Col
  from table1
+8
source

, . script Alter, select, .

+1

Source: https://habr.com/ru/post/1654825/


All Articles