Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to rename a view in MySQL?

Tags:

mysql

I have created a view vw_extr.

Now I want to rename it vw_my.

How can a view be renamed in MySQL?

like image 840
vincy Avatar asked Mar 29 '11 16:03

vincy


People also ask

Can we rename a view in MySQL?

In MySQL, views and tables share the same namespace. Therefore, you can use the RENAME TABLE statement to rename a view.

Can you rename a view in SQL?

Using SQL Server Management Studio In Object Explorer, expand the database that contains the view you wish to rename and then expand the View folder. Right-click the view you wish to rename and select Rename. Enter the view's new name.

How do I change a view in MySQL?

Use the Alter View statement to edit a view. Simply use the existing SQL Statement in the current view, and add the column to the end. A view can only display data from an existing table. You would have to add the column to the table and then modify the view to show it as well.

Which is the correct example to rename the name of view?

To rename the name of a view you follow these steps: First, in Object Explorer, expand the Databases, choose the database name which contains the view that you want to rename and expand the Views folder. Second, right-click the view that you want to rename and select Rename. Third, enter the new name for the view.

How do I rename a table in MySQL view?

In MySQL, views and tables share the same namespace. Therefore, you can use the RENAME TABLE statement to rename a view. Here’s the basic syntax of the RENAME TABLE for renaming a view: RENAME TABLE original_view_name TO new_view_name;

How to change the definition of a view in MySQL?

The MySQL ALTER VIEW statement changes the definition of an existing view. The syntax of the ALTER VIEW is similar to the CREATE VIEW statement: ALTER [ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}] VIEW view_name [ (column_list)] AS select_statement;

What is the MySQL alter View statement?

The MySQL ALTER VIEW statement changes the definition of an existing view. The syntax of the ALTER VIEW is similar to the CREATE VIEW statement: See the following tables orders and orderdetails from the sample database.

How to delete a view from the MySQL database?

Summary: in this tutorial, you will learn how to use the MySQL DROP VIEW statement to delete a view from the database. The DROP VIEW statement deletes a view completely from the database.


2 Answers

You can use RENAME TABLE for that:

RENAME TABLE vw_extr to vw_my 
like image 156
Ike Walker Avatar answered Oct 03 '22 18:10

Ike Walker


Rename didn't work for me, what I did was:

Stop MySQL, change to my database directory, and rename from my_old_view.frm to my_new_view.frm.

I was using linux, so the commands were:

/etc/init.d/mysqld stop cd /var/lib/mysq/DatabaseName mv my_old_view.frm my_new_view.frm /etc/init.d/mysqld start 
like image 29
Alfredo Herrejon Avatar answered Oct 03 '22 18:10

Alfredo Herrejon