Reputation: 1645
How can I update (or edit) a View in MySQL database using phpMyAdmin.
I got a view that's made of columns from two tables - I added a new column to one of these, but the view doesn't have it. I can't find the MySQL query I used to get this view (it's quite obscure one) - so how can I edit the MySQL query that created this view to add a new column into it?
Upvotes: 9
Views: 32348
Reputation: 3339
I know that this is a very old question, but I think this will be helpful to many people as I faced this difficulty finding the Views SQL query.
I'm using Version information: 4.9.11
of phpMyAdmin
and you can find views query in Structure
section of the view and there is Edit View
button under the columns. For better visibility here is screenshot of it:
After this, you can modify your query to show multiple columns in your view.
Upvotes: 1
Reputation: 3831
A Simpler Way
Most of the time, not being able to edit views etc. is due to the DEFINER being set to root@localhost, and if you're coming from a web host control panel, that user is not you.
This has been tested on PHPMyAdmin 4.9.0.1, it may also work on earlier and later versions. PHPMyAdmin seems to remember your username for the rest of the session, so that you can edit freely.
Upvotes: 2
Reputation: 5057
You can also use CREATE OR REPLACE VIEW
, to avoid the step of dropping the view:
show create view viewname
. Find definition in 'Create View' columnCREATE OR REPLACE VIEW
Upvotes: 2
Reputation: 73
To take the view for edit/update,we have used two way:
Step 1:
select your view in phpmyadmin and click Export(make sure click check box of Structure& Add DROP VIEW) & GO.you'll see a CREATE VIEW query like as:CREATE ALGORITHM=UNDEFINED DEFINER=`dbname`@`localhost` SQL SECURITY DEFINER VIEW `vw_name` AS select ..etc..And then remove 'ALGORITHM.....to...DEFINER' part from this query and update/added required field/make changes to the query.and then execute modified view.`
step 2:
Run the query: SHOW CREATE VIEW `vw_name`
Expand the result and choose Full Texts.
Copy entire contents of the Create View column.
Make changes to the query.
Run the query directly (with out the CREATE VIEW... syntax) to make sure it runs as you expect it to.
Upvotes: 3
Reputation: 15335
How about using (Your view is called viewname)
SHOW CREATE VIEW viewname
to get the SQL for the view as it is DROP VIEW viewname
to remove the viewThat would create the view with the additional column(s)
http://dev.mysql.com/doc/refman/5.0/en/show-create-view.html
Upvotes: 9
Reputation: 930
On phpMyADmin Go to Export -> (select) 'Quick - display only the minimal options' -> GO.
That will give you the create statements that you made in a text file, view or save that text file and you should have all the info there.
Upvotes: 1