Is there a way to add a foreign key to a table?
The underlying DBMS all support this, but Drupal7 Core doesn't really care about Foreign Keys (FKs). Views will notice them and use them abit within joins.

Drupal 7 only supports FK in documentation:
http://www.interworks.com/blogs/jkhalaj/2012/04/12/drupal-7-usage-foreign-keys-schema-api-and-current-default-fk-erd

But, if you know this and understand this, then you can still use this foreign key defintion to create the FKs in a module.install file specific to your DBMS.

I use MySQL typically -- and I have done this for a foreign database my settings.php is aware of within a module.install file:

function _idremotedb_add_foreign_keys() {
  $schema = _idremotedb_schema_definition();
  db_set_active('sa_webextracts');
  foreach ($schema as $table =&gt; $table_schema) {
    if (isset($table_schema['foreign keys'])) {
      foreach ($table_schema['foreign keys'] as $fk_name =&gt; $fk_details) {
        $src_col = $fk_details['columns'][0];
        $dest_col = $fk_details['columns'][1];
        $dest_table = $fk_details['table'];
        // Create the FK using your DBMS convention. Change this as necessary
        // or add a lookup to the database handler driver type (mysql, postgres, whatever) ...
        db_query("
          ALTER TABLE $table ADD CONSTRAINT $fk_name
          FOREIGN KEY ($src_col) REFERENCES $dest_table($dest_col);
        ");
        drupal_set_message(t('...added foreign key: !fk', array('!fk' =&gt; $fk_name)));
      }
    }
  }
  // This index added for either mail-list or login.
  #db_add_index('students', 'uniqueidnumber', 'campusuniqueidnumber');
  db_set_active();
}