I am trying to wrap some logic checks in some old company MySQL 5.5 code:
For example,
CREATE TABLE IF NOT EXISTS <table_a> (
blah blah blah
);
I am trying to add a logic so that the query will only be executed when another table exists:
If <table_b> EXISTS
THEN
CREATE TABLE IF NOT EXISTS <table_a> (
blah blah blah
);
END IF;
Here is my query following the MySQL 5.5 syntax (https://dev.mysql.com/doc/refman/5.5/en/if.html)
IF EXISTS(SELECT table_name
FROM INFORMATION_SCHEMA.TABLES
WHERE table_schema = 'table_b_database'
AND table_name = 'table_b')
THEN
CREATE TABLE IF NOT EXISTS <table_a> (
blah blah blah
);
END IF;
Sadly there is an error message:
SQL Error (1064): You have an error in your SQL syntax;
Could any gurus enlighten? Thanks.