

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How can we modify the definition of a MySQL view without dropping it?
<p style="">With the help of ALTER VIEW statement, we can modify the definition of MySQL view. In this case, we do not need to drop it. The syntax would be as follows −</p><h2 style="">Syntax</h2><pre class="prettyprint notranslate">ALTER VIEW view_name AS SELECT column1,column2… FROM table WHERE conditions;</pre><h2 style="">Example</h2><p style="">To illustrate it we are modifying the definition of a view named ‘Info’ which have the following data −</p><pre class="prettyprint notranslate">mysql> Select * from Info; +------+---------+------------+ | Id | Name | Subject | +------+---------+------------+ | 101 | YashPal | History | | 105 | Gaurav | Literature | | 125 | Raman | Computers | | 130 | Ram | Computers | +------+---------+------------+ 4 rows in set (0.01 sec)</pre><p style="">Now, suppose if we want to add one more column in this view then it can be done with the help of ALTER VIEW statement as follows −</p><pre class="prettyprint notranslate">mysql> Alter view info AS SELECT ID, NAME, SUBJECT, ADDRESS from student_info; Query OK, 0 rows affected (0.07 sec) mysql> Select * from info; +------+---------+------------+------------+ | ID | NAME | SUBJECT | ADDRESS | +------+---------+------------+------------+ | 101 | YashPal | History | Amritsar | | 105 | Gaurav | Literature | Chandigarh | | 125 | Raman | Computers | Shimla | | 130 | Ram | Computers | Jhansi | +------+---------+------------+------------+ 4 rows in set (0.00 sec)</pre><p>The above result set shows that column ADDRESS has been added to the view ‘Info’.</p>
- Related Questions & Answers
- How can we get the definition of a MySQL view as we can get the definition of a MySQL table?
- How can we modify a MySQL view with CREATE OR REPLACE VIEW statement?
- How can we modify column/s of MySQL table?
- How can we modify an existing MySQL event?
- How can we get the structure of a MySQL view as we can get the structure of a MySQL table?
- How can we drop a MySQL view from the database?
- How can we list all the columns of a MySQL view as we can list the columns of a MySQL table?
- Dropping a SAP HANA database view
- How can we create a MySQL view based on another existing view?
- 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 the MySQL view with ORDER BY clause?
- There is a DB2 view VIEW1. How to get the definition of this view?
Advertisements