我们如何修改MySQL视图的定义而不删除它?
借助ALTER VIEW语句,我们可以修改MySQL视图的定义。在这种情况下,我们不需要删除它。语法如下-
语法
ALTER VIEW view_name ASSELECT 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;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视图的定义而不删除它? 的全部内容, 来源链接: utcz.com/z/351482.html