This page describes how to create and manage saved queries. When you write SQL scripts in Spanner Studio, you can save and manage those SQL scripts. For more information, see Saved 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 your administrator to grant you the following Identity and Access Management (IAM) roles on the 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 the
Saved queries page: Studio Query Admin (
roles/databasesconsole.studioQueryAdmin
)
For more information about granting roles, see Manage access to projects, folders, and organizations.
These predefined roles contain the permissions required to use saved queries. To learn more about required permissions, see Required permissions.
Required permissions
To create, view, modify, and delete saved queries, you need the following IAM permissions at the project level:
Action | Required IAM permissions |
---|---|
Create saved queries |
|
View saved queries |
|
Modify saved queries |
|
Delete saved queries |
|
Administer saved queries (Only for use by administrators) |
|
The Studio Query User
(roles/databasesconsole.studioQueryUser
)
role provides create, view, and write saved queries access. This role meets
the needs of most users.
Grant the Studio Query Admin
(roles/databasesconsole.studioQueryAdmin
)
role only to administrators. For more information about
Spanner IAM, see IAM overview.
Create a saved query
To create a saved query, follow these steps:
- Go to the Spanner Instances page in the Google Cloud console.
Instances - Select the instance in which you want to create a saved query.
- Select the database in which you want to create a saved query.
- In the navigation menu, click Spanner Studio.
- On the Spanner Studio page, click New tab or use the empty editor tab.
- In the query editor, enter a SQL query.
- Click Save.
- In the Save query dialog, enter a name for the saved query.
- Click Save.
Open and run a saved query
To open a saved query as a new query, follow these steps:
- In the Explorer pane on the Spanner Studio page, navigate to the Queries section.
- Click a saved query to open it in a new editor tab. Optionally, you can click View actions next to a saved query. Then, click Open query to open it in a new editor tab.
- Click Run.
Update a saved query
To update an existing saved query, follow these steps:
- In the Explorer pane on the Spanner Studio page, navigate to the Queries section.
- Click a saved query to open it in a new editor tab. Optionally, you can click View actions next to a saved query. Then, click Open query to open it in a new editor tab.
- Modify the query.
- To save the modified query, click Save.
View and manage a list of all saved queries
To view a list of all saved queries in your project, follow these steps:
- Go to the Spanner Instances page in the Google Cloud console.
Instances - 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.
- Select any database.
- In the Explorer pane on the Spanner Studio page, navigate to the Queries section.
- Click
The Saved queries page opens. This page lists all the saved queries in this project, including saved queries for other Google Cloud products.
View actions next to a saved query. Then, click Manage queries.
You can search, filter, view, and delete queries on the Saved queries page. You can't edit an existing query on the Saved queries page.
Delete a saved query
You can delete a saved query from the Spanner Studio page or on the Saved queries page in the Google Cloud console.
- In the Explorer pane on the Spanner Studio page, navigate to the Queries section.
- Click View actions next to the saved query that you want to delete. Then click Delete query to delete the saved query.
- In the Delete query dialog, click Delete.
You can also delete a saved query on the Saved queries page. To delete a saved query on the Saved queries page, follow these steps:
- Navigate to the Saved queries page.
- Click View actions next to the saved query that you want to delete.
- Click Delete query to delete the saved query.
- In the Delete query dialog, click Delete.
What's next
- Learn about saved queries.