As we all know, we can use ALTER VIEW statement to modify the view, but in addition, we can also use CREATE OR REPLACE VIEW to modify the existing view. The concept is simple, as MySQL only modifies the view if it already exists, otherwise it creates a new view. Following is its syntax -
CREATE OR REPLACE VIEW view_name AS Select_statements FROM table;
mysql> Create OR Replace VIEW Info AS Select Id, Name, Address, Subject from student_info WHERE Subject = 'Computers'; Query OK, 0 rows affected (0.46 sec)
The above query will create or replace the view "Info". If it does not exist yet, it will be created, otherwise it will be replaced by the new definition given in the query above.
The above is the detailed content of How can we modify a MySQL view using CREATE OR REPLACE VIEW statement?. For more information, please follow other related articles on the PHP Chinese website!