How to add new column in existing View in SQL-Server 2014 using Alter

SPBeginer picture SPBeginer · Sep 16, 2016 · Viewed 87k times · Source

I have created a view that is based on another view and a table. I want to add new column of type varchar. I did like below, But getting syntax error? I am new to SQL, So,could not understand

ALTER VIEW [dbo].[MyView]
ADD New_Col varchar(10) null 
GO

Answer

GuidoG picture GuidoG · Sep 16, 2016

you have to write the entire view again and just add or omit what you want to change

for example your view is now :

create view myView as
  select field1
  from table1

and now you want to add a field called New_Col than you write this :

alter view myView as
  select field1,
         New_Col
  from table1