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

僤鯓⒐⒋嵵緔 提交于 2019-11-28 03:37:56

问题


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

回答1:


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



回答2:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!