Home  >  Article  >  Database  >  How can we modify a MySQL view using CREATE OR REPLACE VIEW statement?

How can we modify a MySQL view using CREATE OR REPLACE VIEW statement?

PHPz
PHPzforward
2023-09-12 11:45:141335browse

我们如何使用 CREATE OR REPLACE VIEW 语句修改 MySQL 视图?

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 -

Syntax

CREATE OR REPLACE VIEW view_name AS Select_statements FROM table;

Example

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete