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
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
You can't alter a view like a table. You have to script the view as Alter, and then alter the select statement that generates the view.
来源:https://stackoverflow.com/questions/39535278/how-to-add-new-column-in-existing-view-in-sql-server-2014-using-alter