You are here

protected function Schema::primaryKeyName in Drupal driver for SQL Server and SQL Azure 3.0.x

Same name and namespace in other branches
  1. 8.2 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::primaryKeyName()
  2. 8 drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php \Drupal\Driver\Database\sqlsrv\Schema::primaryKeyName()

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

Parameters

mixed $table: Table name.

4 calls to Schema::primaryKeyName()
Schema::addPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Add a primary key.
Schema::cleanUpPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the primary key constraint.
Schema::cleanUpTechnicalPrimaryColumn in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Tries to clean up the technical primary column.
Schema::dropPrimaryKey in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
Drop the primary key.

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 1875

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

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