Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

up vote 3 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

share|improve this answer

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)

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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