Creating and managing SQL Server databases

This page contains information about creating, listing, and deleting SQL Server databases on a Cloud SQL instance.

For more information about creating SQL Server databases and related topics, see the SQL Server documentation.

For information about setting a default value for the type of collation used for the databases in an instance, see Creating instances.

Before you begin

Before completing the tasks on this page, you must have:

If you plan to use the sqlcmd client to create or manage your databases, you must have:

  • Configured access and connected to the instance with a sqlcmd client.

Creating a database

Follow the rules in Database Identifiers when you create your database name.

To create a database on the Cloud SQL instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Select the instance you want to add the database to.
  3. Select the DATABASES tab.
  4. Click Create database.
  5. In the New database dialog, specify the name of the database.
  6. Click Create.

gcloud

For reference information, see gcloud sql databases create.

For information about collations in SQL Server, see Collation and Unicode Support in the SQL Server documentation.

gcloud sql databases create [DATABASE_NAME] --instance=[INSTANCE_NAME]
[--charset=CHARSET] [--collation=COLLATION]

REST v1beta4

The following request uses the databases:insert method to create a new database on the specified instance.

Before using any of the request data below, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

POST https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases

Request JSON body:

{
  "project": "project-id",
  "instance": "instance-id",
  "name": "database-name"
}

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Listing your databases

To list all databases on an instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Select the instance for which you want to list databases.
  3. Click DATABASES.

    A newly-created instance has a sqlserver database.

gcloud

For reference information, see gcloud sql databases list.

gcloud sql databases list --instance=[INSTANCE_NAME]

REST v1beta4

The following request uses the databases:list method to list the databases for an instance.

When you list the databases using the API, you see additional template databases and a system database that are not displayed by the console. You cannot delete or manage the system database.

Before using any of the request data below, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID

HTTP method and URL:

GET https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

Deleting a database

To delete a database on the Cloud SQL instance:

Console

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.

    Go to the Cloud SQL Instances page

  2. Select the instance that contains the database you want to delete.
  3. Click DATABASES.
  4. In the database list, find the database you want to delete and click the trash can icon.
  5. In the Delete database dialog box, click OK.

gcloud

For reference information, see gcloud sql databases delete.

gcloud sql databases delete [DATABASE_NAME] --instance=[INSTANCE_NAME]

REST v1beta4

The following request uses the databases:delete method to delete the specified database.

Before using any of the request data below, make the following replacements:

  • project-id: The project ID
  • instance-id: The instance ID
  • database-name: The name of a database inside the Cloud SQL instance

HTTP method and URL:

DELETE https://www.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name

To send your request, expand one of these options:

You should receive a JSON response similar to the following:

What's next