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
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
In the Cloud Console, on the project selector page, select or create a Cloud project.
Make sure that billing is enabled for your Google Cloud project. Learn how to confirm 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.
Go to the Cloud SQL Instances page in the Google Cloud Console.
Select your project and click Continue.
Click Create Instance.
Click Choose SQL Server.
myinstancefor Instance ID.
Enter a password for the sqlserver user.
Use the default values for the other fields.
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
- Install the Cloud SDK. The Cloud SDK
gcloudtool to interact with Cloud SQL and other Google Cloud services. The
gcloudtool uses the Admin API to access Cloud SQL, so you must Enable the Admin API before using the
gcloudtool to access Cloud SQL.
- In a bash shell command prompt or in Windows PowerShell,
run the following command to initialize the
- Run the following command to authenticate the
gcloud auth login
- 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.
- Run the Cloud SQL Proxy using a bash shell command prompt
(or using Windows PowerShell). Specifically, run the following command,
Instance-connection-namewith the corresponding value from the Cloud Console's Overview tab (for your instance):
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
In SSMS, select Connect Object Explorer from the File menu.
Enter the following values in the Connection dialog:
- For Server Type, enter Database Engine.
- For Server Name, enter 127.0.0.1 as the IP address of your SQL Server instance.
- For Authentication, enter SQL Server Authentication.
- For Login, enter sqlserver.
- For Password, enter the password used when the instance was created.
Click the Connect button.
Create a database and upload data
In the SSMS Object Explorer window, right-click the Databases node under your instance and select New Database.
Enter testdb for the Database name and click the OK button.
Under the newly created testdb database, right-click the Tables node and select New > Table.
Enter the following values in the Create table dialog:
- In the Properties window, for Identity > Name, enter guestbook.
- For the first Column Name, enter entryID, set its Data Type to
int, and clear the Allow Nulls checkbox.
- In the Column Properties window, expand the Identity Specification item and set (Is Identity) to Yes.
- For the second Column Name, enter guestname and set its Data Type to varchar(255).
- For the third Column Name, enter content and set its Data Type to varchar(255).
Click the File menu and select Save guestbook.
Right-click the testdb table under Databases and select New Query.
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:
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.
The two records you inserted are displayed as Results, along with the SQL
SELECT statement used to query the records.
To avoid incurring charges to your Google Cloud account for the resources used in this quickstart, follow these steps.
- Go to the Cloud SQL Instances page in the Google Cloud Console.
Go to the Cloud SQL Instances page
- Select the
myinstanceinstance to open the Instance details page.
- In the icon bar at the top of the page, click Delete.
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 nextBased on your needs, you can learn more about creating Cloud SQL instances.
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:
- All of the connectivity options in Cloud SQL.
- Configuring your Cloud SQL instance with a public IP address.
- Configuring your Cloud SQL instance with a private IP address.
Additionally, you can learn about connecting to a Cloud SQL instance from other Google Cloud applications: