[[["容易理解","easyToUnderstand","thumb-up"],["確實解決了我的問題","solvedMyProblem","thumb-up"],["其他","otherUp","thumb-up"]],[["難以理解","hardToUnderstand","thumb-down"],["資訊或程式碼範例有誤","incorrectInformationOrSampleCode","thumb-down"],["缺少我需要的資訊/範例","missingTheInformationSamplesINeed","thumb-down"],["翻譯問題","translationIssue","thumb-down"],["其他","otherDown","thumb-down"]],["上次更新時間:2025-09-09 (世界標準時間)。"],[],[],null,["\u003cbr /\u003e\n\n[MySQL](/sql/docs/mysql/create-manage-saved-queries \"View this page for the MySQL database engine\") \\| [PostgreSQL](/sql/docs/postgres/create-manage-saved-queries \"View this page for the PostgreSQL database engine\") \\| SQL Server\n\n\u003cbr /\u003e\n\n|\n| **Preview**\n|\n|\n| This feature is\n|\n| subject to the \"Pre-GA Offerings Terms\" in the General Service Terms section of the\n| [Service Specific Terms](/terms/service-terms#1).\n|\n| Pre-GA features are available \"as is\" and might have limited support.\n|\n| For more information, see the\n| [launch stage descriptions](/products#product-launch-stages).\n\nThis page describes how to create and manage saved queries. When you write\nSQL scripts in Cloud SQL Studio,\nyou can save and manage those SQL scripts. For more information, see [Saved queries overview](/sql/docs/sqlserver/saved-queries)\n.\n\nThe saved queries capability is available only in the Google Cloud console.\n\nRequired roles\n\nTo get the permissions that you need to use saved queries, ask your\nadministrator to grant you the following Identity and Access Management (IAM) roles on\nthe project:\n\n- To view saved queries: Cloud SQL Studio User (`roles/cloudsql.studiouser`)\n- To create, edit, view, and delete saved queries in a project, including access to the **Saved queries** page: Cloud SQL Admin (`roles/cloudsql.admin`) or [Studio Query User](/iam/docs/roles-permissions/databasesconsole) (`roles/databasesconsole.studioQueryUser`)\n- To manage all saved queries in a project, including access to the **Saved queries** page: [Studio Query Admin](/iam/docs/roles-permissions/databasesconsole) (`roles/databasesconsole.studioQueryAdmin`)\n\nFor more information about granting roles, see [Manage access to projects, folders, and organizations](/iam/docs/granting-changing-revoking-access).\n\nThese predefined roles contain the permissions required to use saved\nqueries. To learn more about required permissions, see [Required permissions](#required-permissions).\n\nRequired permissions\n\nTo create, view, modify, and delete saved queries, you need the following IAM\npermissions at the project level:\n\n| **Action** | **Required IAM permissions** |\n|-----------------------------------------------------------|------------------------------------------------------------------------------------------------------------------|\n| Create saved queries | - `databasesconsole.studioQueries.create` |\n| View saved queries | - `databasesconsole.studioQueries.search` - `databasesconsole.locations.get` - `databasesconsole.locations.list` |\n| Modify saved queries | - `databasesconsole.studioQueries.update` |\n| Delete saved queries | - `databasesconsole.studioQueries.delete` |\n| Administer saved queries (Only for use by administrators) | - `databasesConsole.studioQueries.list` \u003c!-- --\u003e - `databasesconsole.locations.list` |\n\n| **Note:** Having access to saved queries doesn't automatically mean that you have permissions to run the query.\n\nYou can also get these permissions using [custom roles](/iam/docs/creating-custom-roles)\nor other [predefined roles](/iam/docs/roles-overview#predefined).\n\nThe [Studio Query User](/iam/docs/roles-permissions/databasesconsole)\n(`roles/databasesconsole.studioQueryUser`)\nrole provides create, view, and write saved queries access. This role meets\nthe needs of most users.\n\nGrant the [Studio Query Admin](/iam/docs/roles-permissions/databasesconsole)\n(`roles/databasesconsole.studioQueryAdmin`)\nrole only to administrators. For more information about\nCloud SQL for SQL Server IAM, see [Roles and permissions](/sql/docs/sqlserver/roles-and-permissions)\n.\n\nCreate a saved query\n\nTo create a saved query, follow these steps:\n\n1. In the Google Cloud console, go to the **Cloud SQL Instances** page.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)\n2. Select the instance in which you want to create a saved query.\n3. In the navigation menu, click **Cloud SQL Studio**.\n4. On the **Cloud SQL Studio** page, click add **New tab** or use the empty editor tab.\n5. In the query editor, enter a SQL query.\n6. Click **Save**.\n7. In the **Save query** dialog, enter a name for the saved query.\n8. Click **Save**.\n\nOpen and run a saved query\n\nTo open a saved query as a new query, follow these steps:\n\n1. In the **Explorer** pane on the **Cloud SQL Studio** page, navigate to the **Queries** section.\n2. Click a saved query to open it in a new editor tab. Optionally, you can click more_vert **View actions** next to a saved query. Then, click **Open query** to open it in a new editor tab.\n3. Click **Run**.\n\nUpdate a saved query\n\nTo update an existing saved query, follow these steps:\n\n1. In the **Explorer** pane on the **Cloud SQL Studio** page, navigate to the **Queries** section.\n2. Click a saved query to open it in a new editor tab. Optionally, you can click more_vert **View actions** next to a saved query. Then, click **Open query** to open it in a new editor tab.\n3. Modify the query.\n4. To save the modified query, click **Save**.\n\nView and manage a list of all saved queries\n\nTo view a list of all saved queries in your project, follow these steps:\n\n1. In the Google Cloud console, go to the **Cloud SQL Instances** page.\n\n [Go to Cloud SQL Instances](https://console.cloud.google.com/sql)\n2. 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.\n3. In the navigation menu, click **Cloud SQL Studio** and [authenticate](/sql/docs/sqlserver/manage-data-using-studio#authentication).\n\n\u003c!-- --\u003e\n\n3. Select any database.\n4. In the **Explorer** pane on the **Cloud SQL Studio** page, navigate to the **Queries** section.\n5. Click more_vert **View actions** next to a saved query. Then, click **Manage queries** .\n\n The **Saved queries** page opens. This page lists all the saved\n queries in this project, including saved queries for other\n Google Cloud products.\n\nYou can search, filter, view, and delete queries on the **Saved queries**\npage. You can't edit an existing query on the **Saved queries** page.\n\nDelete a saved query\n\nYou can delete a saved query from the **Cloud SQL Studio**\npage or on the **Saved queries** page in the Google Cloud console.\n\n1. In the Explorer pane on the **Cloud SQL Studio** page, navigate to the Queries section.\n2. Click more_vert **View actions** next to the saved query that you want to delete. Then click **Delete query** to delete the saved query.\n3. In the **Delete query** dialog, click **Delete**.\n\nYou can also delete a saved query on the **Saved queries** page. To delete a saved query on\nthe **Saved queries** page, follow these steps:\n\n1. Navigate to the [**Saved queries**](#view-and-manage) page.\n2. Click more_vert **View actions** next to the saved query that you want to delete.\n3. Click **Delete query** to delete the saved query.\n4. In the **Delete query** dialog, click **Delete**.\n\nWhat's next\n\n- Learn about [saved queries](/sql/docs/sqlserver/saved-queries)."]]