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 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 IAM roles on the project:
-
To create 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 see the exact permissions that are required, expand the Required permissions section:
Required permissions
The following permissions are required to use saved queries:
-
To create and delete saved queries:
-
databasesConsole.studioQuery.create
-
databasesConsole.studioQuery.update
-
databasesConsole.studioQuery.delete
-
databasesConsole.studioQuery.search
-
-
To manage all saved queries in a project:
-
databasesConsole.studioQuery.create
-
databasesConsole.studioQuery.update
-
databasesConsole.studioQuery.delete
-
databasesConsole.studioQuery.search
-
databasesConsole.studioQuery.list
-
databasesConsole.studioQuery.get
-
You might also be able to get these permissions with custom roles or other predefined roles.
The Studio Query User (roles/databasesConsole.studioQueryUser
) role provides
create, view, and write saved queries access. It is sufficient for most users.
The Studio Query Admin (roles/databasesConsole.studioQueryAdmin
) role should
only be granted to administrators. For more information about
Spanner Identity and Access Management (IAM), see
IAM overview.
Permissions
To create saved queries, you need the following IAM permissions at the project level:
databasesConsole.locations.get
databasesConsole.locations.list
databasesConsole.studioQueries.create
To view saved queries, you need the following permission at the project level:
databasesConsole.studioQueries.search
To modify and delete saved queries, you need the following permission at the project level:
databasesConsole.studioQueries.update
Permissions to execute queries are inherited from the database. It's possible that you might have permissions to view, but not execute a query.
Create a saved query
To create a saved query, follow these steps:
Go to the Spanner Instances page in the Google Cloud console.
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 valid SQL query.
Click Save.
In the Save query dialog, type a name for the saved query.
Click Save.
Open and run a saved query
To open an existing saved query as a new query, follow these steps:
- On the Spanner Studio page, click New tab or use the empty editor tab.
- In the Explorer pane, navigate to the Queries section. Click a saved query to open it in a new editor tab. Alternatively, 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:
- On the Spanner Studio page, click New tab or use the empty editor tab.
- In the Explorer pane, navigate to the Queries section. Click a saved query to open it in a new editor tab. Alternatively, 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.
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.
On the Spanner Studio page, click
New tab or use the empty editor tab.In the Explorer pane, navigate to the Queries section. Click
View actions next to a saved query. Then, click Manage queries.The Saved queries page opens. It 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 the Saved queries page. You can't edit an existing query on the Saved queries page.
To delete a saved query on the Saved queries page, follow these steps:
- 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.
Delete a saved query
- On the Spanner Studio page, click New tab or use the empty editor tab.
- In the Explorer pane, expand the Queries folder. 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.
What's next
- Learn about saved queries.