Export (0) Print
Expand All
1 out of 11 rated this helpful - Rate this topic


This topic is OBSOLETE. You can find the most current version in the SQL 14 Transact-SQL Reference.

This topic is not maintained. For the current version, see CREATE DATABASE.

Creates a new database. You must be connected to the master database to create a new database.

Syntax Conventions (Azure SQL Database)

CREATE DATABASE database_name  [ COLLATE collation_name ]
   (<edition_options> [, ...n]) 

<edition_options> ::= 
   (MAXSIZE = {1 | 5 | 10 | 20 | 30 … 150} GB) 
    |(EDITION = {'web' | 'business'})

To copy a database:
CREATE DATABASE destination_database_name
     AS COPY OF [source_server_name.] source_database_name

This syntax diagram demonstrates the supported arguments in Microsoft Windows Azure SQL Database.

The name of the new database. This name must be unique on the SQL Database server and comply with the SQL Server rules for identifiers. For more information, see Identifiers.

Specifies the default collation for the database. Collation name can be either a Windows collation name or a SQL collation name. If not specified, the database is assigned the default collation, which is SQL_Latin1_General_CP1_CI_AS.

For more information about the Windows and SQL collation names, COLLATE (Transact-SQL).

Specifies the edition of the database, either 'web' for Web Edition or 'business' for Business Edition.

When EDITION is specified but MAXSIZE is not specified, MAXSIZE will be set to the most restrictive size that the edition supports (1 GB for Web Edition and 10 GB for Business Edition).

Specifies the maximum size of the database. MAXSIZE must be valid for the specified EDITION. For Web Edition, valid values of MAXSIZE are: 1GB or 5GB. For Business Edition, valid values are 10GB increments up to 50GB, and then 50 GB increments.

If MAXSIZE is set to a value of 1GB or 5GB and EDITION is not specified, the database edition will automatically be set to Web Edition.

If MAXSIZE is set to a value of 10GB or higher and EDITION is not specified, the database edition will automatically be set to Business Edition.

If neither MAXSIZE nor EDITION are specified a Web Edition database of size 1GB is created.

The name of the database that is created by the database copy. This name must be unique on the (destination) SQL Database server and comply with the SQL Server rules for identifiers. For more information, see Identifiers.

AS COPY OF [source_server_name.]source_database_name
For copying a database to the same or a different SQL Database server.

AS COPY OF cannot be used with any other CREATE DATABASE arguments.

The name of the SQL Database server where the source database is located. This parameter is optional when the source database and the destination database are to be located on the same SQL Database server.

Note: The AS COPY OF argument does not support the fully qualified unique domain names. In other words, if your server's fully qualified domain name is serverName.database.windows.net, use only serverName during database copy.

The name of the database that is to be copied.

Windows Azure SQL Database does not support the following arguments and options when using the CREATE DATABASE statement:

  • Parameters related to the physical placement of file, such as <filespec> and <filegroup>

  • External access options, such as DB_CHAINING and TRUSTWORTHY

  • Attaching a database

  • Service broker options, such as ENABLE_BROKER, NEW_BROKER, and ERROR_BROKER_CONVERSATIONS

  • Database snapshot

For more information about the arguments and the CREATE DATABASE statement, see CREATE DATABASE in SQL Server Books Online.

Databases in Windows Azure SQL Database have several default settings that are set when the database is created. For more information about these default settings, see the list of values in DATABASEPROPERTYEX (Azure SQL Database).

MAXSIZE provides the ability to limit the size of the database. If the size of the database reaches its MAXSIZE you will receive error code 40544. When this occurs, you cannot insert or update data, or create new objects (such as tables, stored procedures, views, and functions). However, you can still read and delete data, truncate tables, drop tables and indexes, and rebuild indexes. You can then update MAXSIZE to a value larger than your current database size or delete some data to free storage space. There may be as much as a fifteen-minute delay before you can insert new data.

The CREATE DATABASE statement must be the only statement in a Transact-SQL batch. You must be connected to the master database when executing the CREATE DATABASE statement.

Database Copies

Copying a database using the CREATE DATABASE statement is an asynchronous operation. Therefore, a connection to the SQL Database server is not needed for the full duration of the copy process. The CREATE DATABASE statement will return control to the user before the database copy operation is complete. In other words, the CREATE DATABASE statement returns successfully when the database copy is still in progress. You can monitor the copy process with the sys.dm_database_copies and sys.databases views. After the copy process completes successfully, the destination database is transactionally consistent with the source database. For more information about copying databases in SQL Database, see Copying Databases in Azure SQL Database.

The following syntax and semantic rules apply to your use of the AS COPY OF argument:

  • The source server name and the server name for the copy target may be the same or different. When they are the same, this parameter is optional and the server context of the current session will be used by default.

  • The source and destination database names must be specified, unique, and comply with the SQL Server rules for identifiers. For more information, see Identifiers.

  • The CREATE DATABASE statement must be executed within the context of the master database of the SQL Database server where the new database will be created.

  • After the copying completes, the destination database must be managed as an independent database. You can execute the ALTER DATABASE and DROP DATABASE statements against the new database independently of the source database. You can also copy the new database to another new database.

  • The destination database cannot be accessed until the copy process is complete. You can check the status of the copy process by querying the state column in the sys.databases view or the percentage_complete column in the sys.dm_database_copies view on the destination SQL Database server.

    During the copy process, the state column of the sys.databases view shows Copying on the destination SQL Database server. In addition, the percentange_complete column of the sys.dm_database_copies shows the percentage of bytes that have been copied on the destination server.

  • The source database may continue to be accessed while the database copy is in progress.

Only the server-level principal login (created by the provisioning process) or members of the dbmanager database role can create databases.

Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

© 2014 Microsoft. All rights reserved.