You are here

protected function Schema::createTableSql in Drupal driver for SQL Server and SQL Azure 8.2

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

Generate SQL to create a new table from a Drupal schema definition.

Parameters

$name: The name of the table to create.

$table: A Schema API table definition array.

Return value

The SQL statement to create the table.

1 call to Schema::createTableSql()
Schema::createTable in drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php
{@Inheritdoc}

File

drivers/lib/Drupal/Driver/Database/sqlsrv/Schema.php, line 371
Definition of Drupal\Driver\Database\sqlsrv\Schema

Class

Schema

Namespace

Drupal\Driver\Database\sqlsrv

Code

protected function createTableSql($name, $table) {
  $sql_fields = [];
  foreach ($table['fields'] as $field_name => $field) {
    $sql_fields[] = $this
      ->createFieldSql($name, $field_name, $this
      ->processField($field));
  }

  // Use already prefixed table name.
  $table_prefixed = $this->connection
    ->prefixTable($name);
  $sql = "CREATE TABLE [{$table_prefixed}] (" . PHP_EOL;
  $sql .= implode("," . PHP_EOL, $sql_fields);
  $sql .= PHP_EOL . ")";
  return $sql;
}