This quickstart shows you how to perform basic operations in Cloud Spanner using the Google Cloud Platform Console. In the quickstart, you will:
- Create a Cloud Spanner instance, database, and table.
- Add a schema.
- Write and modify data.
- Run a query.
Before you begin
-
Sign in to your Google Account.
If you don't already have one, sign up for a new account.
-
Select or create a GCP project.
-
Make sure that billing is enabled for your Google Cloud Platform project.
Create an instance
When you first use Cloud Spanner, you must create an instance, which is an allocation of resources that are used by Cloud Spanner databases in that instance.
Go to the Cloud Spanner Instances page in the GCP Console.
Click Create instance.
For the instance name, enter Test Instance.
For the instance ID, enter test-instance.
Use a Regional configuration.
Choose any regional configuration from the drop-down menu.
Your instance configuration determines the geographic location where your instances are stored and replicated.
Use 1 for the node count.
Your instance creation page now looks like this:
Click Create.
Your instance appears in the instance list.
Create a database
Go to the Cloud Spanner Instances page in the GCP Console.
Click the Test Instance instance.
Click Create database.
For the database name, enter example-db.
Your database creation page now looks like this:
Click Continue.
Skip the Define your database schema step for now. You'll define your schema in the next section of this quickstart.
Click Create.
The GCP Console displays the Database details page after the database is created.
Create a schema for your database
The GCP Console provides two ways to create, alter, and delete tables and indexes in a database:
- By using the default Database editor to specify each part of tables, columns, and indexes.
- By switching the editor to Edit as text mode and entering SQL statements in Cloud Spanner Data Definition Language (DDL) syntax.
This quickstart uses DDL.
- In the left pane of the GCP Console, click the example-db database.
- Click Create table.
- Click the Edit as text toggle.
In the DDL statement field, enter:
CREATE TABLE Singers ( SingerId INT64 NOT NULL, FirstName STRING(1024), LastName STRING(1024), SingerInfo BYTES(MAX), BirthDate DATE, ) PRIMARY KEY(SingerId);Click Create.
This process might take a few minutes. When the operation is complete, the GCP Console displays the details of the table that you created:
Insert and modify data
The GCP Console provides an interface for inserting, editing, and deleting data.
Insert data
- In the left pane of the GCP Console, click Singers.
- Click Data.
- Click Insert.
Enter the following values:
Field Value SingerID:INT64 1BirthDate:DATE [leave blank] FirstName:STRING MarcLastName:STRING RichardsSingerInfo:BYTES [leave blank] Click Save.
The Singers table now has one row:
Click Insert to add an additional row.
Enter the following values:
Field Value SingerID:INT64 2BirthDate:DATE [leave blank] FirstName:STRING CatalinaLastName:STRING SmithSingerInfo:BYTES [leave blank] Click Save.
The Singers table now has two rows:
You can also insert empty string values when you enter data.
- In the left pane, click Singers.
- Click Data.
- Click Insert.
Enter the following values:
Field Value SingerID:INT64 3BirthDate:DATE [leave blank] FirstName:STRING KenaLastName:STRING [check Empty string] SingerInfo:BYTES [leave blank] Click Save.
The Singers table now has three rows, and the row for SingerID
3has a LastName that is an empty string:
Edit data
- In the left pane of the GCP Console, click Singers.
- Click Data.
- Check the box next to the row for SingerId
3, then click Edit. Enter the following value:
Field Value BirthDate:DATE 1961-04-01[all other fields] [leave as-is] Click Save.
The row for SingerId
3in the Singers table now has a BirthDate value:
Delete data
- In the left pane of the GCP Console, click Singers.
- Click Data.
- Check the box next to the row for SingerId
2, then click Delete. In the dialog that appears, click OK.
The Singers table now has two rows:
Run a query
You can now execute a SQL statement on the query page.
- In the left pane of the GCP Console, click example-db to navigate to the Database details page.
- On the Database details page, click Query.
For the query, enter:
SELECT * FROM SingersClick Run query.
The GCP Console displays the result of your query:
Congratulations! You've successfully created a Cloud Spanner database and executed a SQL statement using the query editor!
Cleanup
To avoid additional charges to your Google Cloud Platform account, delete the database and the instance that you created.
Delete the database
Go to the Cloud Spanner Instances page in the Google Cloud Platform Console.
Click Test Instance.
Click example-db.
In the Database details page, click Delete
.Confirm that you want to delete the database and click Delete.
Delete the instance
Deleting an instance automatically deletes all databases created in that instance.
Go to the Cloud Spanner Instances page in the Google Cloud Platform Console.
Click Test Instance.
Click Delete
.Confirm that you want to delete the instance and click Delete.
What's next
- Learn about Instances.
- Understand the Cloud Spanner Schema and Data Model.
- Learn more about Data Definition Language (DDL).
- Learn more about Query Execution Plans.
- Write data into Cloud Spanner using C#, Go, Java, Node.js, PHP, Python, or Ruby.


