You are here

protected function DatabaseSchema_sqlsrv::createTableSql 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::createTableSql()
  2. 7 sqlsrv/schema.inc \DatabaseSchema_sqlsrv::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 DatabaseSchema_sqlsrv::createTableSql()
DatabaseSchema_sqlsrv::createTable in sqlsrv/schema.inc
{@Inheritdoc}

File

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

Class

DatabaseSchema_sqlsrv

Code

protected function createTableSql($name, $table) {
  $sql_fields = array();
  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
    ->prefixTables('{' . $name . '}');
  $sql = "CREATE TABLE [{$table_prefixed}] (" . PHP_EOL;
  $sql .= implode("," . PHP_EOL, $sql_fields);
  $sql .= PHP_EOL . ")";
  return $sql;
}