Create and manage saved queries

Preview

This feature is subject to the "Pre-GA Offerings Terms" in the General Service Terms section of theService Specific Terms. Pre-GA features are available "as is" and might have limited support. For more information, see thelaunch stage descriptions.

This page describes how to create and manage saved queries. When you writeSQL scripts inSpanner Studio,you can save and manage those SQL scripts.For more information, seeSaved queries overview.

The saved queries capability is available only in the Google Cloud console.

Required roles

To get the permissions that you need to use saved queries, ask youradministrator to grant you the following Identity and Access Management (IAM) roles onthe project:

  • To create, edit, and delete saved queries:Studio Query User (roles/databasesconsole.studioQueryUser)
  • To manage all saved queries in a project, including access to theSaved queries page:Studio Query Admin (roles/databasesconsole.studioQueryAdmin)

For more information about granting roles, seeManage access to projects, folders, and organizations.

These predefined roles contain the permissions required to use savedqueries. To learn more about required permissions, seeRequired permissions.

Required permissions

To create, view, modify, and delete saved queries, you need the following IAMpermissions at the project level:

ActionRequired IAM permissions
Create saved queries
  • databasesconsole.studioQueries.create
View saved queries
  • databasesconsole.studioQueries.search
  • databasesconsole.locations.get
  • databasesconsole.locations.list
Modify saved queries
  • databasesconsole.studioQueries.update
Delete saved queries
  • databasesconsole.studioQueries.delete
Administer saved queries
(Only for use by administrators)
  • databasesConsole.studioQueries.list
  • databasesconsole.locations.list
Note: Having access to saved queries doesn't automatically mean that youhave permissions to run the query.

You can also get these permissions usingcustom rolesor otherpredefined roles.

TheStudio Query User (roles/databasesconsole.studioQueryUser) role provides create, view, and write saved queries access. This role meets the needs of most users.

Grant theStudio Query Admin (roles/databasesconsole.studioQueryAdmin)role only to administrators. For more information aboutSpanner IAM, seeIAM overview.

Create a saved query

To create a saved query, follow these steps:

  1. Go to the SpannerInstances page in the Google Cloud console.
    Instances
  2. Select the instance in which you want to create a saved query.
  3. Select the database in which you want to create a saved query.
  4. In the navigation menu, clickSpanner Studio.
  5. On theSpanner Studio page, clickNew tab or use the empty editor tab.
  6. In the query editor, enter a SQL query.
  7. ClickSave.
  8. In theSave query dialog, enter a name for the saved query.
  9. ClickSave.

Open and run a saved query

To open a saved query as a new query, follow these steps:

  1. In theExplorer pane on theSpanner Studio page, navigate to theQueries section.
  2. Click a saved query to open it in a new editor tab. Optionally, you can clickView actions next to a saved query. Then, clickOpen query to open it in a new editor tab.
  3. ClickRun.

Update a saved query

To update an existing saved query, follow these steps:

  1. In theExplorer pane on theSpanner Studio page, navigate to theQueries section.
  2. Click a saved query to open it in a new editor tab. Optionally, you can clickView actions next to a saved query. Then, clickOpen query to open it in a new editor tab.
  3. Modify the query.
  4. To save the modified query, clickSave.

View and manage a list of all saved queries

To view a list of all saved queries in your project, follow these steps:

  1. Go to the SpannerInstances page in the Google Cloud console.
    Instances
  2. Select any instance. Because a saved query is a child of a project, as long as you have the required role, you can view all saved queries in the project from any instance or database.
  1. Select any database.
  2. In theExplorer pane on theSpanner Studio page, navigate to theQueries section.
  3. ClickView actions next to a saved query. Then, clickManage queries.

    TheSaved queries page opens. This page lists all the saved queries in this project, including saved queries for other Google Cloud products.

You can search, filter, view, and delete queries on theSaved queriespage. You can't edit an existing query on theSaved queries page.

Delete a saved query

You can delete a saved query from theSpanner Studiopage or on theSaved queries page in the Google Cloud console.

  1. In theExplorer pane on theSpanner Studio page, navigate to theQueries section.
  2. ClickView actions next to the saved query that you want to delete. Then, to delete the saved query, clickDelete query.
  3. In theDelete query dialog, clickDelete.

You can also delete a saved query on theSaved queries page. To delete a saved query on theSaved queries page, follow these steps:

  1. Navigate to theSaved queries page.
  2. ClickView actions next to the saved query that you want to delete.
  3. ClickDelete query to delete the saved query.
  4. In theDelete query dialog, clickDelete.

What's next

Except as otherwise noted, the content of this page is licensed under theCreative Commons Attribution 4.0 License, and code samples are licensed under theApache 2.0 License. For details, see theGoogle Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.

Last updated 2025-12-15 UTC.