Quickstart for Cloud SQL for SQL Server

This page shows you how to create and connect to a SQL Server instance and perform basic SQL operations using the Google Cloud Console and a client. The resources created in this Quickstart typically cost less than a dollar, assuming you complete the steps, including the clean up, in a timely manner.

Before you begin

  1. Sign in to your Google Account.

    If you don't already have one, sign up for a new account.

  2. In the Google Cloud Console, on the project selector page, select or create a Google Cloud project.

    Go to the project selector page

  3. Make sure that billing is enabled for your Cloud project. Learn how to confirm that billing is enabled for your project.

Create an instance

In this procedure, you use the Cloud Console. To use gcloud or cURL, see Creating instances.

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

    Go to the Cloud SQL Instances page

  2. Select your project and click Continue.

  3. Click Create Instance.

  4. Click Choose SQL Server.

  5. Enter myinstance for Instance ID.

  6. Enter a password for the sqlserver user.

  7. Use the default values for the other fields.

  8. Click Create.

    You are returned to the instances list; you can click into the new instance right away to see the details, but it won't be available until it initializes and starts.

Connect to your instance using SQL Server Management Studio

  1. Install the Cloud SDK. The Cloud SDK provides the gcloud tool to interact with Cloud SQL and other Google Cloud services. The gcloud tool uses the Admin API to access Cloud SQL, so you must Enable the Admin API before using the gcloud tool to access Cloud SQL.
  2. In a bash shell command prompt or in Windows PowerShell, run the following command to initialize the gcloud tool:
    gcloud init
    
  3. Run the following command to authenticate the gcloud tool:
    gcloud auth login
    
  4. Download and install the Google Cloud SQL Proxy (see Installing the Cloud SQL Proxy). Note the location of the Cloud SQL Proxy because you will run the proxy in next step.
  5. Run the Cloud SQL Proxy using a bash shell command prompt (or using Windows PowerShell). Specifically, run the following command, replacing Instance-connection-name with the corresponding value from the Cloud Console's Overview tab (for your instance):
    ./cloud_sql_proxy -instances=[Instance-connection-name]=tcp:1433
    

For more information about installing and using the proxy, see About the Cloud SQL Proxy.

As described in the next section, now you can connect to your SQL Server instance using SSMS and the localhost IP address.

Connect using the SSMS Object Explorer

  1. In SSMS, select Connect Object Explorer from the File menu.

    Selecting the Object Explorer

  2. Enter the following values in the Connection dialog:

    1. For Server Type, enter Database Engine.
    2. For Server Name, enter 127.0.0.1 as the IP address of your SQL Server instance.
    3. For Authentication, enter SQL Server Authentication.
    4. For Login, enter sqlserver.
    5. For Password, enter the password used when the instance was created.
  3. Click the Connect button.

Create a database and upload data

  1. In the SSMS Object Explorer window, right-click the Databases node under your instance and select New Database.

    Selecting New Database

  2. Enter testdb for the Database name and click the OK button.

    Enter database name of testdb in the dialog

  3. Under the newly created testdb database, right-click the Tables node and select New > Table.

    Select New Table

  4. Enter the following values in the Create table dialog:

    1. In the Properties window, for Identity > Name, enter guestbook.
    2. For the first Column Name, enter entryID, set its Data Type to int, and clear the Allow Nulls checkbox.
      1. In the Column Properties window, expand the Identity Specification item and set (Is Identity) to Yes.
    3. For the second Column Name, enter guestname and set its Data Type to varchar(255).
    4. For the third Column Name, enter content and set its Data Type to varchar(255).

    Enter values for a table

  5. Click the File menu and select Save guestbook.

    Save the guestbook table

  6. Right-click the testdb table under Databases and select New Query.

    For testdb, select New Query

  7. Enter the following two INSERT statements into the SQL query text window and click the Execute button.

    INSERT INTO guestbook (guestName, content) values ('first guest', 'I got here!');
    
    INSERT INTO guestbook (guestName, content) values ('second guest', 'Me too!');
    

    As an example: Enter two Insert statements

  8. Expand the Tables item under the Databases > testdb item in the Object Explorer window. Right-click the dbo.guestbook table and choose Select Top 1000 Rows.

    Select the top rows

The two records you inserted are displayed as Results, along with the SQL SELECT statement used to query the records.

View the results of your query

Clean up

To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.

  1. Go to the Cloud SQL Instances page in the Google Cloud Console.
    Go to the Cloud SQL Instances page
  2. Select the myinstance instance to open the Instance details page.
  3. In the icon bar at the top of the page, click Delete.
  4. In the Delete instance window, type myinstance, then click Delete to delete the instance.

    You cannot reuse an instance name for about 7 days after an instance is deleted.

What's next

Based on your needs, you can learn more about creating Cloud SQL instances.

You also can learn about creating SQL Server users and databases for your Cloud SQL instance.

Also see the Cloud SQL pricing information.

In this quickstart you connected to the instance using Cloud Shell. In most use cases, how you connect depends on your networking configuration, such as:

  • If your Cloud SQL instance has a public or private IP address.
  • If you're connecting from inside Google Cloud (from the same project or from a different project).
  • If you're connecting from outside of Google Cloud.

Learn more about:

Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications: