MySQL

How to Update a View in MySQL

In this tutorial, we are going to see how to update a view in MySQL. In MySQL, a view is not a physical table, but rather a virtual table created by a query joining one or more tables. You can change the definition of a view in MySQL without deleting it simply by using the ALTER VIEW statement.
 

Syntax:

The syntax of the statement ALTER VIEW in MySQL is as follows:

ALTER VIEW viewName AS
  SELECT column1, column2, ...
  FROM tableName
  WHERE conditions;

 

 

Example: How to Update a View in MySQL

Here is an example of using the ALTER VIEW statement in MySQL:

ALTER VIEW stock_vw AS
  SELECT product, qt
  FROM stock
  WHERE qt >= 20;

This query will update the definition of the view named “stock_vw” without deleting it.

mcqMCQPractice competitive and technical Multiple Choice Questions and Answers (MCQs) with simple and logical explanations to prepare for tests and interviews.Read More

Leave a Reply

Your email address will not be published. Required fields are marked *