您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

我们怎样才能修改MySQL视图的定义而不删除它呢?

2024/2/25 6:56:36发布18次查看
借助alter view语句,我们可以修改mysql视图的定义。在这种情况下,我们不需要删除它。语法如下 -
语法alter view view_name asselect column1,column2…from tablewhere 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视图的定义而不删除它呢?的详细内容。
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product