Title: Create Table &#8211; multiple unique keys
Last modified: August 22, 2016

---

# Create Table – multiple unique keys

 *  [edtiley](https://wordpress.org/support/users/edtiley/)
 * (@edtiley)
 * [11 years, 4 months ago](https://wordpress.org/support/topic/create-table-multiple-unique-keys/)
 * I’m working on a plugin that creates a custom table. I’m trying to add a second
   UNIQUE KEY so the $wpdb->insert will fail if a duplicate value is specified.
   
   dbDelta() has no problem with:
 *     ```
       $sql = "CREATE TABLE " . $table_name . " (
            group_id int unsigned NOT NULL AUTO_INCREMENT,
            creation_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            group_title tinytext NOT NULL,
            UNIQUE KEY  id (group_id)
            );";
       ```
   
 * But the table does not get added if I add a second UNIQUE KEY:
 *     ```
       $sql = "CREATE TABLE " . $table_name . " (
            group_id int unsigned NOT NULL AUTO_INCREMENT,
            creation_date datetime DEFAULT '0000-00-00 00:00:00' NOT NULL,
            group_title tinytext NOT NULL,
            UNIQUE KEY  id (group_id),
            UNIQUE KEY  group (group_title)
            );";
       ```
   
 * What am I missing? Everything I’ve read says you can create multiple UNIQUE KEYs,
   but I can’t seem to get it working.
 * Thanks,
    Ed

The topic ‘Create Table – multiple unique keys’ is closed to new replies.

## Tags

 * [dbDelta()](https://wordpress.org/support/topic-tag/dbdelta/)
 * [wpdb](https://wordpress.org/support/topic-tag/wpdb/)

 * 0 replies
 * 1 participant
 * Last reply from: [edtiley](https://wordpress.org/support/users/edtiley/)
 * Last activity: [11 years, 4 months ago](https://wordpress.org/support/topic/create-table-multiple-unique-keys/)
 * Status: not resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
