You are here

protected function DatabaseSchema_sqlsrv::primaryKeyName in Drupal driver for SQL Server and SQL Azure 7

Same name and namespace in other branches
  1. 7.3 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::primaryKeyName()
  2. 7.2 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::primaryKeyName()

Return the name of the primary key of a table if it exists.

4 calls to DatabaseSchema_sqlsrv::primaryKeyName()
DatabaseSchema_sqlsrv::addPrimaryKey in sqlsrv/schema.inc
Override DatabaseSchema::addPrimaryKey().
DatabaseSchema_sqlsrv::cleanUpTechnicalPrimaryColumn in sqlsrv/schema.inc
Try to clean up the technical primary column if possible.
DatabaseSchema_sqlsrv::dropPrimaryKey in sqlsrv/schema.inc
Override DatabaseSchema::dropPrimaryKey().
DatabaseSchema_sqlsrv::recreatePrimaryKey in sqlsrv/schema.inc

File

sqlsrv/schema.inc, line 822
Database schema code for Microsoft SQL Server database servers.

Class

DatabaseSchema_sqlsrv

Code

protected function primaryKeyName($table) {
  $table = $this->connection
    ->prefixTables('{' . $table . '}');
  return $this->connection
    ->query('SELECT name FROM sys.key_constraints WHERE parent_object_id = OBJECT_ID(:table) AND type = :type', array(
    ':table' => $table,
    ':type' => 'PK',
  ))
    ->fetchField();
}