![]() Use the RENAME TABLE statement to rename a view.GROUP BY productLine Code language: SQL (Structured Query Language) ( sql ) Summary Third, change the name of the view the CREATE VIEW statement and execute it: CREATE VIEW categorySales AS SELECT Second, drop the view productLineQtySales: DROP VIEW productLineQtySales Code language: SQL (Structured Query Language) ( sql ) Note that you should copy the statement in the Create View column. This means that if there is a crash (server down or power outage) during RENAME TABLE, all tables will revert to their original names and any changes to trigger files will be reverted. Suppose you want to change the name of the view productLineQtySales to categorySales.įirst, use the SHOW CREATE VIEW to get the view’s definition: SHOW CREATE VIEW productLineQtySales Code language: SQL (Structured Query Language) ( sql ) From MariaDB 10.6, RENAME TABLE is atomic for most engines, including InnoDB, MyRocks, MyISAM and Aria ( MDEV-23842 ). Third, use the SHOW FULL TABLES to check if the view has been renamed successfully: SHOW FULL TABLES WHERE table_type = 'VIEW' Code language: SQL (Structured Query Language) ( sql ) 2) Renaming a view using the DROP VIEW and CREATE VIEW sequence example TO productLineQtySales Code language: SQL (Structured Query Language) ( sql ) Second, rename the view productLineSales to productLineQtySales: RENAME TABLE productLineSales Third, use the FIRST or AFTER columnname option to determine the new position of the column. Second, specify the column name and the new name followed by column definition after the CHANGE COLUMN keywords. First, specify the name of the table to which the column belongs. GROUP BY productLine Code language: SQL (Structured Query Language) ( sql ) MySQL ALTER TABLE Rename a column in a table. 1) Renaming a view using the RENAME TABLE statement exampleįirst, create a new view called productLineSales for the demonstration: CREATE VIEW productLineSales AS SELECT Let’s take some examples of renaming a view. Note that by using a sequence of DROP VIEW and CREATE VIEW statements, you can also move a view from one database to another. Finally, execute the CREATE VIEW statement to create the view with the new name.After that, change the name of the view in the CREATE VIEW statement.Then, drop the view using the DROP VIEW statement.Next, copy the CREATATE VIEW statement and save it to a file.First, get the CREATE VIEW statement by using the SHOW CREATE VIEW statement.If you attempt to do so, MySQL will issue an error.Īnother indirect way to rename a view is to use a sequence of the DROP VIEW and CREATE VIEW statement. Note that you cannot use the RENAME TABLE statement to move a view from one database to another. Then, specify the new name of the view after the TO keyword.First, specify the view’s name that you want to rename after the RENAME TABLE keywords.TO new_view_name Code language: SQL (Structured Query Language) ( sql ) Here’s the basic syntax of the RENAME TABLE for renaming a view: RENAME TABLE original_view_name Therefore, you can use the RENAME TABLE statement to rename a view. ![]() In MySQL, views and tables share the same namespace. Introduction to the RENAME TABLE statement Summary: in this tutorial, you will learn how to rename a view in MySQL using the RENAME TABLE statement or a sequence of DROP VIEW and CREATE VIEW statements.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |