How to remove a unique key in an update hook I have a primary key and a unique key in my modules' schema.  I need to remove the unique key.

To remove an an index it is simple: 

function draggableviews_update_7205() {
  if (db_index_exists('draggableviews_structure', 'entity_id')) {
    db_drop_index('draggableviews_structure', 'entity_id', array('entity_id'));
  }
}


There is a db_index_exists() function.  There is db_drop_unique_key() and db_add_unique_key() function, but no db_unique_key_exist().

How do I remove the unique key in an update hook?
All of the core schema classes (mysql, pgsql &amp; sqlite) check for the existence of the constraint before actually dropping, so you don't have to check yourself. If you do you're actually doubling up on a DB op unnecessarily.

To cover all eventualities your code could look something like this:

try {
  if (db_drop_unique_key($table, $name)) {
    // Constraint was found and removed.
  }
  else {
    // Constraint was not found, nothing was altered.
  }
}
catch (PDOException $e) {
  // Constraint was found, but something went wrong, see $e-&gt;getMessage() for more info.
  throw new DrupalUpdateException($e-&gt;getMessage);
}


Incidentally, a unique constraint is treated the same as an index by the core schema classes, so db_index_exists() can be used to check for them too.