如何使用 Alter 在 SQL-Server 2014 的现有视图中添加新列 [英] How to add new column in existing View in SQL-Server 2014 using Alter

查看:27
本文介绍了如何使用 Alter 在 SQL-Server 2014 的现有视图中添加新列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个基于另一个视图和表的视图.我想添加 varchar 类型的新列.我喜欢下面,但语法错误?我是 SQL 新手,所以,无法理解

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

例如你现在的观点是:

create view myView as
  select field1
  from table1

现在你想添加一个名为 New_Col 的字段,而不是你写这个:

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

这篇关于如何使用 Alter 在 SQL-Server 2014 的现有视图中添加新列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆