Checking if Database Table exists

I read the wordpress codex and professional wordpress. It seems both use something like

if($wpdb->get_var("SHOW TABLES LIKE '$table_name'") != $table_name) {

to determine if the table exists. Is there any reason why CREATE TABLE IF NOT EXISTS ( ... ) is not used? It will check and create the table in 1 query, won’t it be better? Or am I missing something?

7

If you use “IF NOT EXISTS” then the dbdelta script will not upgrade your database with delta’s appeared after the initial creation of the database.

(assuming you want to re-use the same sql script)

at least… that is what i think

Leave a Comment