Thursday, 15 March 2012

sql server - How do I add columns to a view? -


Is there a way to add a new column and update them in the view?

Columns are not in a table; I want to select some columns from a table, then add some new columns and update them.

I tried ALTER VIEW to add columns, but he gave me an error:

Change to 'viewName'

See the documentation.

You can not add columns for a new view, you can just include the full query in your view.

For exmaple, if I was:

  View MyView as User ID, Users Username   

And then wanted to add DateCreated to my selection list, I will write:

  ALTER VIEW MyView as UserID, UserName, Date dated by users   

Alternatively, you can simply see DROP and create it with the new column as well.

No comments:

Post a Comment