1.20.x schema.inc public DatabaseSchema::cloneTable($source, $target)

Create an exact duplicate of an existing table, including all content.

Parameters

$source: The name of the table to be copied.

$target: The name of the new table to be created and populated with data.

Throws

DatabaseSchemaObjectExistsException If the new table specified already exists.

File

includes/database/schema.inc, line 750
Generic Database schema code.

Class

DatabaseSchema
Base class for database schema definitions.

Code

public function cloneTable($source, $target) {
  if ($this->tableExists($target)) {
    throw new DatabaseSchemaObjectExistsException(t('Table @name already exists.', array('@name' => $target)));
  }
  $statements = $this->cloneTableSql($source, $target);
  foreach ($statements as $statement) {
    $this->connection->query($statement);
  }
}