How to add columns to a view in SQL Server 2005 How to add columns to a view in SQL Server 2005 database database

How to add columns to a view in SQL Server 2005


You can use ALTER VIEW to achieve the result you are looking for.

This will just act as dropping the existing view and adding new columns from your new select statement. However, this is better than dropping your existing view and creating a new view because the Alter view will retain the permissions granted to users.


If these 4 columns are calculated based on existing data then you just need to run ALTER VIEW... and add them into the query definition used by the view

ALTER VIEW dbo.foo ASSELECT originalcolumnlist, A+B AS col1, C+D as col2, E+F as col3, G+H as col4FROM yourtable

You can right click the View definition in Management Studio and "Script View as -> Alter" to see the existing definition.


alter view TheViewName
as
select oldCol_A, oldCol_B, NEWCol_C
from someTable

go