借助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視圖的定義而不刪除它呢?的詳細內容,更多請關注www.92cms.cn其它相關文章!