create view purchase_detail as select product.name as name, product .price as price, purchase.qty as qty, product .price * purchase.qty as total_value from product, purchase where product.product_id = purchase.product_id;
alter [algorithm = {undefined | merge | temptable}] view view_name [(column_list)] as select_statement [with [cascaded | local] check option]该语句用于更改已有视图的定义。其语法与create view类似。
2. 使用举例
eg. 将上一小节中中创建的视purchase_detail进行修改,去掉qty列,语句如下:
alter view purchase_detail as select product.name as name, product .price as price, product .price * purchase.qty as total_value from product, purchase where product.product_id = purchase.product_id;
此时通过语句:select * from purchase_detail;对视图进行查询时,结果如下: