How can I see the Original MySQL used to create a view in phpMyAdmin or other program?

zechdc picture zechdc · Sep 9, 2011 · Viewed 7.4k times · Source

How can I see the original MySQL used to create a view in phpMyAdmin or other program?

I am using phpMyAdmin version 3.3.9.

This post tells how to see the SQL used to create a view but its not the original SQL used. How can I edit a view using phpMyAdmin 3.2.4?

The code returned works, it just doesn't have my original format making it harder to edit. Is there a program to make this easier or do I need to save my original SQL in a text file somewhere?

Example:

SQL Used:

CREATE VIEW `wheel`.`new_view` AS
SELECT
`t_ci_sessions`.`session_id`,
`t_ci_sessions`.`ip_address`,
`t_ci_sessions`.`user_agent`,
`t_ci_sessions`.`last_activity`,
`t_ci_sessions`.`user_data`
FROM `wheel`.`t_ci_sessions`;
SELECT * FROM `wheel`.`ci_sessions`;

SQL phpMyAdmin Returns:

CREATE ALGORITHM=UNDEFINED DEFINER=`root`@`localhost` SQL SECURITY DEFINER VIEW `new_view` AS select `t_ci_sessions`.`session_id` AS `session_id`,`t_ci_sessions`.`ip_address` AS `ip_address`,`t_ci_sessions`.`user_agent` AS `user_agent`,`t_ci_sessions`.`last_activity` AS `last_activity`,`t_ci_sessions`.`user_data` AS `user_data` from `t_ci_sessions`

Answer

Bohemian picture Bohemian · Sep 9, 2011

You can't find out the exact SQL used to create a view, but you can see the parsed version of it, which will of course be very close and semantically exactly the same, using this command:

show create view my_view_name;