You are here

protected function DatabaseSchema_sqlsrv::cleanUpPrimaryKey in Drupal driver for SQL Server and SQL Azure 7.2

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

Drop the primary key constraint.

Parameters

mixed $table:

5 calls to DatabaseSchema_sqlsrv::cleanUpPrimaryKey()
DatabaseSchema_sqlsrv::changeField in sqlsrv/schema.inc
Override DatabaseSchema::changeField().
DatabaseSchema_sqlsrv::compressPrimaryKeyIndex in sqlsrv/schema.inc
Sometimes the size of a table's primary key index needs to be reduced to allow for Primary XML Indexes.
DatabaseSchema_sqlsrv::dropFieldRelatedObjects in sqlsrv/schema.inc
Drop the related objects of a column (indexes, constraints, etc.).
DatabaseSchema_sqlsrv::dropPrimaryKey in sqlsrv/schema.inc
Override DatabaseSchema::dropPrimaryKey().
DatabaseSchema_sqlsrv::recreatePrimaryKey in sqlsrv/schema.inc
Drops the current primary key and creates a new one. If the previous primary key was an internal primary key, it tries to cleant it up.

File

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

Class

DatabaseSchema_sqlsrv

Code

protected function cleanUpPrimaryKey($table) {

  // We are droping the constraint, but not the column.
  if ($existing_primary_key = $this
    ->primaryKeyName($table)) {
    $this->connection
      ->query_direct("ALTER TABLE [{{$table}}] DROP CONSTRAINT {$existing_primary_key}");
  }

  // We are using computed columns to store primary keys,
  // try to remove it if it exists.
  if ($this
    ->fieldExists($table, $this->COMPUTED_PK_COLUMN_NAME)) {

    // The TCPK has compensation indexes that need to be cleared.
    $this
      ->dropIndex($table, $this->COMPUTED_PK_COLUMN_INDEX);
    $this
      ->dropField($table, $this->COMPUTED_PK_COLUMN_NAME);
  }

  // Try to get rid of the TPC
  $this
    ->cleanUpTechnicalPrimaryColumn($table);
}