Create view if a table exists

SurSild's profile image SurSild posted 5 years ago in General Permalink

Hi,

So I want to write a procedure to create a view, but only if a certain table exists. If it doesn't exist I don't want it to do anything. So something like this:

If table_X exists THEN CREATE VIEW table_X_view AS SELECT distance_start10 as distance_km, distance_end10 as distance_end_km FROM table_X

I've tried many different possibilities, but I just can't figure it out.

ansgar's profile image ansgar posted 5 years ago Permalink

Which server is it? And probably also mention the version.

SurSild's profile image SurSild posted 5 years ago Permalink

I use MySQL, and am using Heidi SQL version 10.2.0.5599. If this didn't answear your question, please give me more info about how to answer you as I am not that good with these technical stuff.

ansgar's profile image ansgar posted 5 years ago Permalink

There are a couple of ways to check if a table exist:

https://www.electrictoolbox.com/check-if-mysql-table-exists/

Please login to leave a reply, or register at first.