WordPress.org

Codex

Attention Interested in functions, hooks, classes, or methods? Check out the new WordPress Code Reference!

Function Reference/dbDelta

The dbDelta function looks at the current table structure, compares it to the desired table structure passed to the function, and either adds or modifies the table. It is often used in plugins to create (if the table doesn't exist) or update the table structure. Read more about creating tables in WordPress here: http://codex.wordpress.org/Creating_Tables_with_Plugins.

In order for the function to work correctly, the SQL statement must use the following criteria:

1. You have to put each field on its own line in your SQL statement.

2. You have to have two spaces between the words PRIMARY KEY and the definition of your primary key.

3. You must use the key word KEY rather than its synonym INDEX and you must include at least one KEY.