How to update a view in phpMyAdmin?
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.
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' column- use below command to add new columns:
CREATE OR REPLACE VIEW
How about using (Your view is called viewname)
SHOW CREATE VIEW viewname
to get the SQL for the view as it isDROP VIEW viewname
to remove the view- Modify the SQL from the first step to add the new column to that SQL
- Run the modified SQL
That would create the view with the additional column(s)
http://dev.mysql.com/doc/refman/5.0/en/show-create-view.html
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.
- Click Home (house icon) top left, copy your username to the right.
- Click your view on the left > Structure > Edit View and edit.
- Paste your username in place of 'root@localhost' and click Go.
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.