Lit Aiy Lit Aiy - 3 months ago 12
SQL Question

Check if view exists in mysql

I have a mysql view called

records_latest
. What query can I use to check if this view already exists in mysql database?

I create this view in a script during start-up. I do not wish to create it more than once. So, I need to check if the view exists or not.

Answer

To show a list of views that are in you database the

SHOW FULL TABLES IN youdatabasename WHERE TABLE_TYPE LIKE '%VIEW%';

if you want to create a view with that name and you don't care how the view was before you can use the

CREATE OR REPLACE VIEW  records_latest ....

this will delete the previous view if it exists and then will create the view again

Comments