语法
ALTER VIEW view_name AS
SELECT column1,column2…
FROM table
WHERE conditions;
登录后复制
示例
为了说明这一点,我们正在修改名为“Info”的视图的定义,该视图具有以下数据 -
mysql> Select * from Info;
+------+---------+------------+
| Id | Name | Subject |
+------+---------+------------+
| 101 | YashPal | History |
| 105 | Gaurav | Literature |
| 125 | Raman | Computers |
| 130 | Ram | Computers |
+------+---------+------------+
4 rows in set (0.01 sec)
登录后复制
现在,假设如果我们想在此视图中再添加一列,则可以借助 ALTER VIEW 语句来完成,如下所示 -
mysql> Alter view info AS SELECT ID, NAME, SUBJECT, ADDRESS from student_info;
Query OK, 0 rows affected (0.07 sec)
mysql> Select * from info;
+------+---------+------------+------------+
| ID | NAME | SUBJECT | ADDRESS |
+------+---------+------------+------------+
| 101 | YashPal | History | Amritsar |
| 105 | Gaurav | Literature | Chandigarh |
| 125 | Raman | Computers | Shimla |
| 130 | Ram | Computers | Jhansi |
+------+---------+------------+------------+
4 rows in set (0.00 sec)
登录后复制
上面的结果集显示列 ADDRESS 已添加到视图“Info”中。
以上就是我们怎样才能修改MySQL视图的定义而不删除它呢?的详细内容,更多请关注每日运维网(www.mryunwei.com)其它相关文章!