- Learn MySQL
- MySQL - Home
- MySQL - Introduction
- MySQL - Installation
- MySQL - Administration
- MySQL - PHP Syntax
- MySQL - Connection
- MySQL - Create Database
- MySQL - Drop Database
- MySQL - Select Database
- MySQL - Data Types
- MySQL - Create Tables
- MySQL - Drop Tables
- MySQL - Insert Query
- MySQL - Select Query
- MySQL - Where Clause
- MySQL - Update Query
- MySQL - Delete Query
- MySQL - Like Clause
- MySQL - Sorting Results
- MySQL - Using Join
- MySQL - NULL Values
- MySQL - Regexps
- MySQL - Transactions
- MySQL - Alter Command
- MySQL - Indexes
- MySQL - Temporary Tables
- MySQL - Clone Tables
- MySQL - Database Info
- MySQL - Using Sequences
- MySQL - Handling Duplicates
- MySQL - SQL Injection
- MySQL - Database Export
- MySQL - Database Import
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 −
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 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.
- Related Articles
- How can we create a MySQL view with a subquery?
- How can we create a MySQL view with LEFT JOIN?
- How can we create a MySQL view with INNER JOIN?
- How can we create a MySQL view with RIGHT JOIN?
- How can we create a MySQL view based on another existing view?
- How can we create a MySQL view with GROUP BY clause?
- How can we modify the definition of a MySQL view without dropping it?
- How can we create the MySQL view with ORDER BY clause?
- How can we create a MySQL view by using data from multiple tables?
- How to create a MySQL view?
- How can we drop a MySQL view from the database?
- How can we create a MySQL view by selecting some range of values from a base table?
- How do I create a view in MySQL?
- How can we create MySQL view by selecting data based on pattern matching from base table?
- How to create a table from view in MySQL?