借助ALTER VIEW语句,我们可以修改MySQL视图的定义。在这种情况下,我们不需要删除它。语法如下 -
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视图的定义而不删除它呢?的详细内容。更多信息请关注PHP中文网其他相关文章!