Quickstart Using the Console

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

  1. Sign in to your Google account.

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

  2. Select or create a Cloud Platform project.

    Go to the Manage resources page

  3. Enable billing for your project.

    Enable billing

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.

  1. Go to the Spanner page in the Cloud Platform Console.
    Go to the Spanner page
  2. Click Create instance.
  3. For the instance name, enter Test Instance.
  4. For the instance ID, enter test-instance.
  5. Use a Regional configuration.
  6. Choose any regional configuration from the drop-down menu.
    Your instance configuration determines the geographic location where your instances are stored and replicated.
  7. Use 1 for the node count.
    Your instance creation page now looks like this:

    Screenshot of the instance creation window

  8. Click Create.

Your instance appears in the Spanner Instances page.

Create a database

  1. Go to the Spanner Instances page in the Cloud Platform Console.
    Go to the Spanner Instances page
  2. Click the Test Instance instance.
  3. Click Create database.
  4. For the database name, enter example-db. Your database creation page now looks like this:

    Screenshot of the database creation window

  5. Skip the Define your database schema step for now. You'll define your schema in the next section of this quickstart.

  6. Click Create.

The Cloud Platform Console displays the Database details page after the database is created.

Create a schema for your database

The Cloud Platform 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.

  1. In the left pane of the Cloud Platform Console, click the example-db database.
  2. Click Create table.
  3. Click the Edit as text toggle.
  4. 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);
    

  5. Click Create table.
    This may take a few minutes to finish. When the operation is complete, the Cloud Platform Console displays the details of the table that you created:

    Screenshot of table

Insert and modify data

The Cloud Platform Console provides an interface for inserting, editing, and deleting data.

Insert data

  1. In the left pane of the Cloud Platform Console, click Singers.
  2. Click Data.
  3. Click Insert.
  4. Enter the following values:

    Field Value
    SingerID:INT64 1
    BirthDate:DATE [leave blank]
    FirstName:STRING Marc
    LastName:STRING Richards
    SingerInfo:BYTES [leave blank]
  5. Click Save.
    The Singers table now has one row:
    Screenshot of Singers table data with one row

  6. Click Insert to add an additional row.
  7. Enter the following values:

    Field Value
    SingerID:INT64 2
    BirthDate:DATE [leave blank]
    FirstName:STRING Catalina
    LastName:STRING Smith
    SingerInfo:BYTES [leave blank]
  8. Click Save.
    The Singers table now has two rows:
    Screenshot of Singers table data with two rows

You can also insert empty string values when you enter data.

  1. In the left pane, click Singers.
  2. Click Data.
  3. Click Insert.
  4. Enter the following values:

    Field Value
    SingerID:INT64 3
    BirthDate:DATE [leave blank]
    FirstName:STRING Kena
    LastName:STRING [check empty string]
    SingerInfo:BYTES [leave blank]
  5. Click Save.
    The Singers table now has three rows, and the row for SingerID 3 has a LastName that is an empty string:
    Screenshot of Singers table data with three rows

Edit data

  1. In the left pane of the Cloud Platform Console, click Singers.
  2. Click Data.
  3. Check the box next to the row for SingerId 3, then click Edit.
  4. Enter the following value:

    Field Value
    BirthDate:DATE 1961-04-01
    [all other fields] [leave as-is]
  5. Click Save.
    The row for SingerId 3 in the Singers table now has a BirthDate value:
    Screenshot of Singers table data with three rows, the third of which now contains a BirthDate value

Delete data

  1. In the left pane of the Cloud Platform Console, click Singers.
  2. Click Data.
  3. Check the box next to the row for SingerId 2, then click Delete.
  4. In the dialog that appears, click OK.
  5. Click Save.
    The Singers table now has two rows:
    Screenshot of Singers table data with two rows; the row for SingerId 2 is gone

Run a query

You can now execute a SQL statement on the query page.

  1. In the left pane of the Cloud Platform Console, click example-db to navigate to the Database details page.
  2. On the Database details page, click Query.
  3. For the query, enter:

    SELECT * FROM Singers
    
  4. Click Run query.
    The Cloud Platform Console displays the result of your query:

    Screenshot of query results

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

  1. Go to the Spanner Instances page in the Google Cloud Platform Console.
    Go to the Spanner Instances page
  2. Click Test Instance.
  3. Click example-db.
  4. In the Database details page, click Delete Screenshot of delete UI element.
  5. 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.

  1. Go to the Spanner Instances page in the Google Cloud Platform Console.
    Go to the Spanner Instances page
  2. Click Test Instance.
  3. Click Delete Screenshot of delete UI element.
  4. Confirm that you want to delete the instance and click Delete.

What's next

Send feedback about...

Cloud Spanner Documentation