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


As we know that we can modify a view by using ALTER VIEW statement but other than that we can also use CREATE OR REPLACE VIEW to modify an existing view. The concept is simple as MySQL simply modifies the view if it already exists otherwise a new view would be created. Following is the syntax of it −

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 a view ‘Info’. It will be created if not existed already otherwise it would get replaced by a new definition given in the above query.

Updated on: 22-Jun-2020

340 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements