借助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中文網其他相關文章!