Create and manage databases  |  Cloud SQL for SQL Server  |  Google Cloud (2024)

MySQL | PostgreSQL | SQL Server

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

A newly-created instance has a sqlserver database.

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 ofcollationused for the databases in an instance, see Creating instances.

Before you begin

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

  • Created a Cloud SQL instance. For more information,see Creating instances.

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.

Create a database on the Cloud SQL instance

Console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Select Databases from the SQL navigation menu.
  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]

Terraform

To create a database, use a Terraform resource.

resource "google_sql_database" "database" { name = "my-database" instance = google_sql_database_instance.instance.name}

Apply the changes

To apply your Terraform configuration in a Google Cloud project, complete the steps in the following sections.

Prepare Cloud Shell

  1. Launch Cloud Shell.
  2. Set the default Google Cloud project where you want to apply your Terraform configurations.

    You only need to run this command once per project, and you can run it in any directory.

    export GOOGLE_CLOUD_PROJECT=PROJECT_ID

    Environment variables are overridden if you set explicit values in the Terraform configuration file.

Prepare the directory

Each Terraform configuration file must have its own directory (alsocalled a root module).

  1. In Cloud Shell, create a directory and a new file within that directory. The filename must have the .tf extension—for example main.tf. In this tutorial, the file is referred to as main.tf.
    mkdir DIRECTORY && cd DIRECTORY && touch main.tf
  2. If you are following a tutorial, you can copy the sample code in each section or step.

    Copy the sample code into the newly created main.tf.

    Optionally, copy the code from GitHub. This is recommended when the Terraform snippet is part of an end-to-end solution.

  3. Review and modify the sample parameters to apply to your environment.
  4. Save your changes.
  5. Initialize Terraform. You only need to do this once per directory.
    terraform init

    Optionally, to use the latest Google provider version, include the -upgrade option:

    terraform init -upgrade

Apply the changes

  1. Review the configuration and verify that the resources that Terraform is going to create or update match your expectations:
    terraform plan

    Make corrections to the configuration as necessary.

  2. Apply the Terraform configuration by running the following command and entering yes at the prompt:
    terraform apply

    Wait until Terraform displays the "Apply complete!" message.

  3. Open your Google Cloud project to view the results. In the Google Cloud console, navigate to your resources in the UI to make sure that Terraform has created or updated them.

Delete the changes

To delete your changes, do the following:

  1. To disable deletion protection, in your Terraform configuration file set the deletion_protection argument to false.
    deletion_protection = "false"
  2. Apply the updated Terraform configuration by running the following command and entering yes at the prompt:
    terraform apply
  1. Remove resources previously applied with your Terraform configuration by running the following command and entering yes at the prompt:

    terraform destroy

REST v1

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

Before using any of the request data, 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://sqladmin.googleapis.com/v1/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:

curl (Linux, macOS, or Cloud Shell)

Save the request body in a file named request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "CREATE_DATABASE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id", "targetProject": "project-id"}

REST v1beta4

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

Before using any of the request data, 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://sqladmin.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:

curl (Linux, macOS, or Cloud Shell)

Save the request body in a file named request.json, and execute the following command:

curl -X POST \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
-H "Content-Type: application/json; charset=utf-8" \
-d @request.json \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Save the request body in a file named request.json, and execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method POST `
-Headers $headers `
-ContentType: "application/json; charset=utf-8" `
-InFile request.json `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "CREATE_DATABASE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id"}

List your databases

To list all databases on an instance:

Console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Click Databases from the left side menu. The Databases page lists databases along with their collation type, character set, and database type.

gcloud

For reference information, see gcloud sql databases list.

gcloud sql databases list \--instance=INSTANCE_NAME

REST v1

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

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

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

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

HTTP method and URL:

GET https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#database", "charset": "utf8", "collation": "utf8_general_ci", "etag": "etag", "name": "sys", "instance": "instance-id", "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/sys", "project": "project-id"}

REST v1beta4

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

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

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

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

HTTP method and URL:

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

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Execute the following command:

curl -X GET \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases"

PowerShell (Windows)

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method GET `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#database", "charset": "utf8", "collation": "utf8_general_ci", "etag": "etag", "name": "sys", "instance": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/sys", "project": "project-id"}

Delete a database

To delete a database on the Cloud SQL instance:

Console

  1. In the Google Cloud console, go to the Cloud SQL Instances page.

    Go to Cloud SQL Instances

  2. To open the Overview page of an instance, click the instance name.
  3. Click Databases from the left side menu.
  4. In the database list, find the database you want to delete and click the trash can icon.
  5. In the Delete database dialog, enter the name of the database and then click Delete.

gcloud

For reference information, see gcloud sql databases delete.

gcloud sql databases delete DATABASE_NAME \--instance=INSTANCE_NAME

REST v1

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

Before using any of the request data, 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://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name"

PowerShell (Windows)

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id/databases/database-name" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/v1/projects/project-id/instances/instance-id", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "DELETE_DATABASE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/v1/projects/project-id/operations/operation-id", "targetProject": "project-id"}

REST v1beta4

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

Before using any of the request data, 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://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name

To send your request, expand one of these options:

curl (Linux, macOS, or Cloud Shell)

Execute the following command:

curl -X DELETE \
-H "Authorization: Bearer $(gcloud auth print-access-token)" \
"https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name"

PowerShell (Windows)

Execute the following command:

$cred = gcloud auth print-access-token
$headers = @{ "Authorization" = "Bearer $cred" }

Invoke-WebRequest `
-Method DELETE `
-Headers $headers `
-Uri "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id/databases/database-name" | Select-Object -Expand Content

You should receive a JSON response similar to the following:

Response

{ "kind": "sql#operation", "targetLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/instances/instance-id", "status": "PENDING", "user": "user@example.com", "insertTime": "2020-01-21T22:43:37.981Z", "operationType": "DELETE_DATABASE", "name": "operation-id", "targetId": "instance-id", "selfLink": "https://sqladmin.googleapis.com/sql/v1beta4/projects/project-id/operations/operation-id", "targetProject": "project-id"}

What's next

Try it for yourself

If you're new to Google Cloud, create an account to evaluate how Cloud SQL performs in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.

Try Cloud SQL free

Create and manage databases  |  Cloud SQL for SQL Server  |  Google Cloud (2024)

FAQs

How do I create a SQL database in Google Cloud? ›

  1. In the Google Cloud console, go to the Cloud SQL Instances page. Go to Cloud SQL Instances.
  2. To open the Overview page of an instance, click the instance name.
  3. Select Databases from the SQL navigation menu.
  4. Click Create database.
  5. In the New database dialog, specify the name of the database.
  6. Click Create.

Which are the following databases you can manage using Cloud SQL service in Google Cloud? ›

Cloud SQL is a service that delivers fully managed relational databases in the cloud. It offers MySQL, PostgreSQL, and SQL Server database engines.

Which database you should use if you want a SQL database for cloud? ›

Microsoft Azure SQL Database

Azure is a robust cloud provider with a massive infrastructure only beaten by AWS. It offers an SQL database service that makes it easy for developers to build apps. Setting up Azure SQL database is noticeably quick and easy; you need a Microsoft account to do this.

Can you run SQL Server on Google Cloud? ›

SQL Server running on Google Cloud works with all of your familiar tools like SSMS and Visual Studio. Connect your existing workloads to the best of what Google Cloud has to offer.

What SQL is used in Google Cloud? ›

Google Cloud SQL is a fully managed database service that makes it easy to set up, maintain, manage and administer your relational MySQL, PostgreSQL and SQL Server databases in the cloud. Hosted on Google Cloud, Cloud SQL provides a database infrastructure for applications running anywhere.

What is the difference between SQL Server and Cloud SQL? ›

Ecosystem and Community: Google Cloud SQL has a growing ecosystem, with support from various third-party tools and libraries. However, it may have a smaller community compared to Microsoft SQL Server, which has a large user base, extensive documentation, and a vast community of developers and resources available.

What are the three types of cloud databases? ›

They all support both IaaS and DBaaS environments on their own platforms and offer different types of cloud databases, including relational, NoSQL, data warehouse and special-purpose ones.

Does Google use SQL databases? ›

Many applications running on Compute Engine, App Engine and other services in Google Cloud use Cloud SQL for database storage.

How do I upload data to Google Cloud SQL? ›

In the Google Cloud console, go to the Cloud SQL Instances page. To open the Overview page of an instance, click the instance name. Click Import. In the Choose the file you'd like to import data from section, enter the path to the bucket and CSV file to use for the import.

Can I host a database on Google Cloud? ›

Google Cloud offers a managed MySQL database built to suit your business needs, from retiring your on-premises data center, to running SaaS applications, to migrating core business systems.

Is Google Cloud SQL free? ›

New customers also get $300 in free credits to spend on Cloud SQL to run, test, and deploy workloads. You won't be charged until you upgrade. Sign up to try Cloud SQL for free.

How do I host a MySQL database on Google Cloud? ›

Create a Database Instance
  1. Open your Google Cloud account and click SQL in the left menu.
  2. Click Create Instance.
  3. Choose your database engine. ...
  4. Choose an Instance ID. ...
  5. Select a root password.
  6. Choose the region. ...
  7. Click Show configuration options to expand the configuration options.

How do I create a table in Google Cloud database? ›

You can create an empty table with a schema definition in the following ways:
  1. Enter the schema using the Google Cloud console.
  2. Provide the schema inline using the bq command-line tool.
  3. Submit a JSON schema file using the bq command-line tool.
  4. Provide the schema in a table resource when calling the APIs tables.

How do I access Google Cloud SQL database? ›

Using the client in the Cloud Shell
  1. Go to the Google Cloud console. Go to the Google Cloud console.
  2. Click the Cloud Shell icon towards the right in the toolbar. The Cloud Shell takes a few moments to initialize.
  3. At the Cloud Shell prompt, use the built-in client to connect to your Cloud SQL instance: ...
  4. Enter your password.

Top Articles
It's Official: Microsoft Office Will Soon Become Microsoft 365
How to Get Microsoft Word, Excel and PowerPoint for Free
Amtrust Bank Cd Rates
Shs Games 1V1 Lol
Konkurrenz für Kioske: 7-Eleven will Minisupermärkte in Deutschland etablieren
Lesson 1 Homework 5.5 Answer Key
Bbc 5Live Schedule
Ncaaf Reference
Luciipurrrr_
Nichole Monskey
R Tiktoksweets
Jesus Calling Oct 27
Teenleaks Discord
Bcbs Prefix List Phone Numbers
Cocaine Bear Showtimes Near Regal Opry Mills
Quick Answer: When Is The Zellwood Corn Festival - BikeHike
Woodmont Place At Palmer Resident Portal
Www.publicsurplus.com Motor Pool
Dtlr Duke St
Ac-15 Gungeon
Doki The Banker
Www.dunkinbaskinrunsonyou.con
Egizi Funeral Home Turnersville Nj
Wisconsin Volleyball Team Boobs Uncensored
Living Shard Calamity
What we lost when Craigslist shut down its personals section
The Goonies Showtimes Near Marcus Rosemount Cinema
2021 Tesla Model 3 Standard Range Pl electric for sale - Portland, OR - craigslist
Dl.high Stakes Sweeps Download
Scat Ladyboy
Fedex Walgreens Pickup Times
Craigslist Maryland Baltimore
Unity Webgl Player Drift Hunters
Heavenly Delusion Gif
Housing Intranet Unt
Jason Brewer Leaving Fox 25
Mid America Clinical Labs Appointments
sacramento for sale by owner "boats" - craigslist
Sound Of Freedom Showtimes Near Lewisburg Cinema 8
Payrollservers.us Webclock
Yale College Confidential 2027
Arcanis Secret Santa
Mauston O'reilly's
The Complete Uber Eats Delivery Driver Guide:
Bank Of America Appointments Near Me
Paradise leaked: An analysis of offshore data leaks
Stephen Dilbeck, The First Hicks Baby: 5 Fast Facts You Need to Know
Julies Freebies Instant Win
Hampton Inn Corbin Ky Bed Bugs
Diesel Technician/Mechanic III - Entry Level - transportation - job employment - craigslist
Mike De Beer Twitter
Latest Posts
Article information

Author: Carlyn Walter

Last Updated:

Views: 5854

Rating: 5 / 5 (70 voted)

Reviews: 85% of readers found this page helpful

Author information

Name: Carlyn Walter

Birthday: 1996-01-03

Address: Suite 452 40815 Denyse Extensions, Sengermouth, OR 42374

Phone: +8501809515404

Job: Manufacturing Technician

Hobby: Table tennis, Archery, Vacation, Metal detecting, Yo-yoing, Crocheting, Creative writing

Introduction: My name is Carlyn Walter, I am a lively, glamorous, healthy, clean, powerful, calm, combative person who loves writing and wants to share my knowledge and understanding with you.