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?

link|improve this question

feedback

2 Answers

up vote 1 down vote accepted

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

link|improve this answer
feedback

DISCLAIMER : I'm not a WordPress Guru, only a MySQL DBA

If you want to user a different query, try this

SELECT COUNT(1) FROM information_schema.tables WHERE table_schema='dbname' AND table_name='tbname';

It will either return 0 (if table does not exist) or 1 (if table does exist)

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.