Same name in this branch
  1. 6.x includes/database.pgsql.inc \db_add_primary_key()
  2. 6.x includes/database.mysql-common.inc \db_add_primary_key()
Same name and namespace in other branches
  1. 7.x includes/database/database.inc \db_add_primary_key()
  2. 8.9.x core/includes/database.inc \db_add_primary_key()

Add a primary key.

Parameters

$ret: Array to which query results will be added.

$table: The table to be altered.

$fields: Fields for the primary key.

Related topics

7 calls to db_add_primary_key()
system_update_6001 in modules/system/system.install
Add version id column to {term_node} to allow taxonomy module to use revisions.
system_update_6002 in modules/system/system.install
Increase the maximum length of variable names from 48 to 128.
system_update_6019 in modules/system/system.install
Reconcile small differences in the previous, manually created mysql and pgsql schemas so they are the same and can be represented by a single schema structure.
system_update_6022 in modules/system/system.install
Update files tables to associate files to a uid by default instead of a nid. Rename file_revisions to upload since it should only be used by the upload module used by upload to link files to nodes.
system_update_6033 in modules/system/system.install
Change node_comment_statistics to be not autoincrement.

... See full list

File

includes/database.mysql-common.inc, line 381
Functions shared between mysql and mysqli database engines.

Code

function db_add_primary_key(&$ret, $table, $fields) {
  $ret[] = update_sql('ALTER TABLE {' . $table . '} ADD PRIMARY KEY (' . _db_create_key_sql($fields) . ')');
}