Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 8c8889c

Browse files
authored
Merge pull request #32277 from MicrosoftDocs/main
11/01/2024 PM Publish
2 parents bd1b838 + 04058a9 commit 8c8889c

File tree

3 files changed

+135
-108
lines changed

3 files changed

+135
-108
lines changed

docs/relational-databases/system-catalog-views/sys-query-store-query-hints-transact-sql.md

Lines changed: 40 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "sys.query_store_query_hints (Transact-SQL)"
33
description: The sys.query_store_query_hints system catalog view returns Query Store hints.
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: 10/14/2022
6+
ms.date: 11/01/2024
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: "language-reference"
@@ -17,31 +17,36 @@ helpviewer_keywords:
1717
- "query_store_query_hints catalog view"
1818
dev_langs:
1919
- "TSQL"
20-
monikerRange: "=azuresqldb-current||=azuresqldb-mi-current||>=sql-server-ver16||>=sql-server-linux-ver16"
20+
monikerRange: "=azuresqldb-current || =azuresqldb-mi-current || >=sql-server-ver16 || >=sql-server-linux-ver16"
2121
---
2222
# sys.query_store_query_hints (Transact-SQL)
23+
2324
[!INCLUDE [sqlserver2022-asdb-asmi](../../includes/applies-to-version/sqlserver2022-asdb-asmi.md)]
2425

25-
Returns query hints from [Query Store hints](../../relational-databases/performance/query-store-hints.md).
26-
27-
|Column name|Data type|Description|
28-
|-----------------|---------------|-----------------|
29-
|**query_hint_id**|bigint|Unique identifier of a query hint.|
30-
|**query_id**|bigint|Unique identifier of a query in the Query Store. Foreign key to [sys.query_store_query](sys-query-store-query-transact-sql.md).query_id.)|
31-
|**query_hint_text**|nvarchar(MAX)|Hint definition in form of N'OPTION (…) |
32-
|**last_query_hint_failure_reason**|int|Error code returned when if applying hints failed. Will include the message_id of the error message.|
33-
|**last_query_hint_failure_reason_desc**|nvarchar(128)|Will include the error description of the error message.|
34-
|**query_hint_failure_count**|bigint|Number of times that the query hint application has failed since the query hint was created or last modified. |
35-
|**source**|int|Source of Query Store hint: user source is zero and system-generated is non-zero. |
36-
|**source_desc**|nvarchar(128)|Description of source of Query Store hint.|
37-
|**comment**|nvarchar(max)|Internal use only.|
38-
|**query_hint_scope**| tinyint | Determines the scope at which the hint will be applied, as per the `replica_group_id` column in [sys.query_store_replicas](../system-catalog-views/sys-query-store-replicas.md). |
26+
Returns query hints from [Query Store hints](../performance/query-store-hints.md).
27+
28+
| Column name | Data type | Description |
29+
| --- | --- | --- |
30+
| `query_hint_id` | **bigint** | Unique identifier of a query hint. |
31+
| `query_id` | **bigint** | Unique identifier of a query in the Query Store. Foreign key to the `query_id` column in [sys.query_store_query](sys-query-store-query-transact-sql.md). |
32+
| `query_hint_text` | **nvarchar(max)** | Hint definition in form of `N'OPTION (...)` |
33+
| `last_query_hint_failure_reason` | **int** | Error code returned when if applying hints failed. Includes the `message_id` of the error message. |
34+
| `last_query_hint_failure_reason_desc` | **nvarchar(128)** | Includes the error description of the error message. |
35+
| `query_hint_failure_count` | **bigint** | Number of times that the query hint application failed since the query hint was created or last modified. |
36+
| `source` | **int** | Source of Query Store hint: user source is zero and system-generated is non-zero. |
37+
| `source_desc` | **nvarchar(128)** | Description of source of Query Store hint. |
38+
| `comment` | **nvarchar(max)** | Internal use only. |
39+
| `query_hint_scope` | **tinyint** | Determines the scope at which the hint is applied, as per the `replica_group_id` column in [sys.query_store_replicas](sys-query-store-replicas.md). |
3940

4041
## Remarks
41-
Query Store hints are created by [sys.sp_query_store_set_hints (Transact-SQL)](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md) and removed by [sys.sp_query_store_clear_hints](../system-stored-procedures/sys-sp-query-store-clear-hints-transact-sql.md).
4242

43-
## Permissions
44-
Requires the **VIEW DATABASE STATE** permission.
43+
Query Store hints are created by [sys.sp_query_store_set_hints](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md) and removed by [sys.sp_query_store_clear_hints](../system-stored-procedures/sys-sp-query-store-clear-hints-transact-sql.md).
44+
45+
## Permissions
46+
47+
[!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and previous versions require `VIEW SERVER STATE` permission on the server.
48+
49+
[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions require `VIEW SERVER PERFORMANCE STATE` permission on the server.
4550

4651
## Examples
4752

@@ -50,13 +55,21 @@ monikerRange: "=azuresqldb-current||=azuresqldb-mi-current||>=sql-server-ver16||
5055
The following example returns existing Query Store hints for `query_id` 39:
5156

5257
```sql
53-
SELECT query_hint_id, query_id, query_hint_text, last_query_hint_failure_reason, last_query_hint_failure_reason_desc, query_hint_failure_count, source, source_desc
54-
FROM sys.query_store_query_hints
58+
SELECT query_hint_id,
59+
query_id,
60+
query_hint_text,
61+
last_query_hint_failure_reason,
62+
last_query_hint_failure_reason_desc,
63+
query_hint_failure_count,
64+
source,
65+
source_desc
66+
FROM sys.query_store_query_hints
5567
WHERE query_id = 39;
5668
```
57-
58-
## Next steps
59-
- [Query Store hints](../../relational-databases/performance/query-store-hints.md)
60-
- [sys.sp_query_store_set_hints](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md)
61-
- [sys.sp_query_store_clear_hints](../system-stored-procedures/sys-sp-query-store-clear-hints-transact-sql.md)
62-
- [sys.query_store_query (Transact-SQL)](sys-query-store-query-transact-sql.md)
69+
70+
## Related content
71+
72+
- [Query Store hints](../performance/query-store-hints.md)
73+
- [sys.sp_query_store_set_hints](../system-stored-procedures/sys-sp-query-store-set-hints-transact-sql.md)
74+
- [sys.sp_query_store_clear_hints](../system-stored-procedures/sys-sp-query-store-clear-hints-transact-sql.md)
75+
- [sys.query_store_query (Transact-SQL)](sys-query-store-query-transact-sql.md)

docs/relational-databases/system-catalog-views/sys-query-store-query-text-transact-sql.md

Lines changed: 34 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: "sys.query_store_query_text (Transact-SQL)"
33
description: sys.query_store_query_text (Transact-SQL)
44
author: rwestMSFT
55
ms.author: randolphwest
6-
ms.date: "01/23/2019"
6+
ms.date: 11/01/2024
77
ms.service: sql
88
ms.subservice: system-objects
99
ms.topic: "reference"
@@ -17,35 +17,40 @@ helpviewer_keywords:
1717
- "query_store_query_text catalog view"
1818
dev_langs:
1919
- "TSQL"
20-
monikerRange: "=azuresqldb-current||>=sql-server-2016||=azure-sqldw-latest||>=sql-server-linux-2017||=azuresqldb-mi-current"
20+
monikerRange: "=azuresqldb-current || >=sql-server-2016 || =azure-sqldw-latest || >=sql-server-linux-2017 || =azuresqldb-mi-current"
2121
---
2222
# sys.query_store_query_text (Transact-SQL)
23+
2324
[!INCLUDE [sqlserver2016-asdb-asdbmi-asa](../../includes/applies-to-version/sqlserver2016-asdb-asdbmi-asa.md)]
2425

25-
Contains the [!INCLUDE[tsql](../../includes/tsql-md.md)] text and the SQL handle of the query.
26-
27-
|Column name|Data type|Description|
28-
|-----------------|---------------|-----------------|
29-
|**query_text_id**|**bigint**|Primary key.|
30-
|**query_sql_text**|**nvarchar(max)**|SQL text of the query, as provided by the user. Includes whitespaces, hints and comments. Comments and spaces before and after the query text are ignored. Comments and spaces inside text are not ignored.|
31-
|**statement_sql_handle**|**varbinary(64)**|SQL handle of the individual query.|
32-
|**is_part_of_encrypted_module**|**bit**|Query text is a part of an encrypted module.<br/>**Note:** Azure Synapse Analytics will always return zero (0).|
33-
|**has_restricted_text**|**bit**|Query text contains a password or other unmentionable words.<br/>**Note:** Azure Synapse Analytics will always return zero (0).|
34-
35-
## Permissions
36-
Requires the **VIEW DATABASE STATE** permission.
37-
38-
## See Also
39-
[sys.database_query_store_options &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-database-query-store-options-transact-sql.md)
40-
[sys.query_context_settings &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-context-settings-transact-sql.md)
41-
[sys.query_store_plan &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-store-plan-transact-sql.md)
42-
[sys.query_store_query &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-store-query-transact-sql.md)
43-
[sys.query_store_runtime_stats &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-store-runtime-stats-transact-sql.md)
44-
[sys.query_store_wait_stats &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-store-wait-stats-transact-sql.md)
45-
[sys.query_store_runtime_stats_interval &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/sys-query-store-runtime-stats-interval-transact-sql.md)
46-
[Monitoring Performance By Using the Query Store](../../relational-databases/performance/monitoring-performance-by-using-the-query-store.md)
47-
[Catalog Views &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/catalog-views-transact-sql.md)
48-
[Query Store Stored Procedures &#40;Transact-SQL&#41;](../../relational-databases/system-stored-procedures/query-store-stored-procedures-transact-sql.md)
49-
[sys.fn_stmt_sql_handle_from_sql_stmt &#40;Transact-SQL&#41;](../../relational-databases/system-functions/sys-fn-stmt-sql-handle-from-sql-stmt-transact-sql.md)
50-
51-
26+
Contains the [!INCLUDE [tsql](../../includes/tsql-md.md)] text and the SQL handle of the query.
27+
28+
| Column name | Data type | Description |
29+
| --- | --- | --- |
30+
| `query_text_id` | **bigint** | Primary key. |
31+
| `query_sql_text` | **nvarchar(max)** | SQL text of the query, as provided by the user. Includes whitespaces, hints, and comments. Comments and spaces before and after the query text are ignored. Comments and spaces inside text aren't ignored. |
32+
| `statement_sql_handle` | **varbinary(64)** | SQL handle of the individual query. |
33+
| `is_part_of_encrypted_module` <sup>1</sup> | **bit** | Query text is a part of an encrypted module. |
34+
| `has_restricted_text` <sup>1</sup> | **bit** | Query text contains a password or other unmentionable words. |
35+
36+
<sup>1</sup> Azure Synapse Analytics always returns zero (`0`).
37+
38+
## Permissions
39+
40+
[!INCLUDE [sssql19-md](../../includes/sssql19-md.md)] and previous versions require `VIEW SERVER STATE` permission on the server.
41+
42+
[!INCLUDE [sssql22-md](../../includes/sssql22-md.md)] and later versions require `VIEW SERVER PERFORMANCE STATE` permission on the server.
43+
44+
## Related content
45+
46+
- [sys.database_query_store_options (Transact-SQL)](sys-database-query-store-options-transact-sql.md)
47+
- [sys.query_context_settings (Transact-SQL)](sys-query-context-settings-transact-sql.md)
48+
- [sys.query_store_plan (Transact-SQL)](sys-query-store-plan-transact-sql.md)
49+
- [sys.query_store_query (Transact-SQL)](sys-query-store-query-transact-sql.md)
50+
- [sys.query_store_runtime_stats (Transact-SQL)](sys-query-store-runtime-stats-transact-sql.md)
51+
- [sys.query_store_wait_stats (Transact-SQL)](sys-query-store-wait-stats-transact-sql.md)
52+
- [sys.query_store_runtime_stats_interval (Transact-SQL)](sys-query-store-runtime-stats-interval-transact-sql.md)
53+
- [Monitor performance by using the Query Store](../performance/monitoring-performance-by-using-the-query-store.md)
54+
- [System catalog views (Transact-SQL)](catalog-views-transact-sql.md)
55+
- [Query Store stored procedures (Transact-SQL)](../system-stored-procedures/query-store-stored-procedures-transact-sql.md)
56+
- [sys.fn_stmt_sql_handle_from_sql_stmt (Transact-SQL)](../system-functions/sys-fn-stmt-sql-handle-from-sql-stmt-transact-sql.md)
Lines changed: 61 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
---
22
title: "sys.fn_hadr_backup_is_preferred_replica (Transact-SQL)"
3-
description: "sys.fn_hadr_backup_is_preferred_replica (Transact-SQL)"
3+
description: sys.fn_hadr_backup_is_preferred_replica is used to determine if the current replica is the preferred backup replica.
44
author: MikeRayMSFT
55
ms.author: mikeray
6-
ms.date: "03/16/2017"
6+
ms.reviewer: randolphwest
7+
ms.date: 11/01/2024
78
ms.service: sql
89
ms.subservice: system-objects
910
ms.topic: "reference"
@@ -19,58 +20,66 @@ helpviewer_keywords:
1920
dev_langs:
2021
- "TSQL"
2122
---
22-
# sys.fn_hadr_backup_is_preferred_replica (Transact-SQL)
23+
# sys.fn_hadr_backup_is_preferred_replica (Transact-SQL)
24+
2325
[!INCLUDE [SQL Server](../../includes/applies-to-version/sqlserver.md)]
2426

25-
Used to determine if the current replica is the preferred backup replica.
26-
27-
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
28-
29-
## Syntax
30-
27+
Used to determine if the current replica is the preferred backup replica.
28+
29+
:::image type="icon" source="../../includes/media/topic-link-icon.svg" border="false"::: [Transact-SQL syntax conventions](../../t-sql/language-elements/transact-sql-syntax-conventions-transact-sql.md)
30+
31+
## Syntax
32+
3133
```syntaxsql
32-
sys.fn_hadr_backup_is_preferred_replica ( 'dbname' )
33-
```
34-
35-
## Arguments
36-
'*dbname*'
37-
Is the name of the database to be backed up. *dbname* is type sysname.
38-
39-
## Returns
40-
Returns data type **bool**: 1 if the database on the current instance is on the preferred replica, otherwise 0.
41-
42-
## Remarks
43-
Use this function in a backup script to determine if the current database is on the replica that is preferred for backups. You can run a script on every availability replica. Each of these jobs looks at the same data to determine which job should run, so only one of the scheduled jobs actually proceeds to the backup stage. Sample code could be similar to the following.
44-
45-
```sql
46-
If sys.fn_hadr_backup_is_preferred_replica( @dbname ) <> 1
47-
BEGIN
34+
sys.fn_hadr_backup_is_preferred_replica ( 'dbname' )
35+
```
36+
37+
## Arguments
38+
39+
#### '*dbname*'
40+
41+
The name of the database to be backed up. *dbname* is type sysname.
42+
43+
## Returns
44+
45+
Returns data type **bit**: `1` if the database on the current instance is on the preferred replica, otherwise `0`.
46+
47+
For databases that aren't part of an availability group, this function always returns `1`.
48+
49+
## Remarks
50+
51+
Use this function in a backup script to determine if the current database is on the replica that is preferred for backups. You can run a script on every availability replica. Each of these jobs looks at the same data to determine which job should run, so only one of the scheduled jobs actually proceeds to the backup stage. Sample code could be similar to the following.
52+
53+
```sql
54+
IF sys.fn_hadr_backup_is_preferred_replica(@dbname) <> 1
55+
BEGIN
4856
-- If this is not the preferred replica, exit (probably without error).
49-
Select 'This is not the preferred replica, exiting with success';
50-
END
51-
-- If this is the preferred replica, continue to do the backup.
52-
/* actual backup command goes here */
53-
```
54-
55-
## Examples
56-
57-
### A. Using sys.fn_hadr_backup_is_preferred_replica
58-
The following example returns 1 if the current database is the preferred backup replica.
59-
57+
SELECT 'This is not the preferred replica, exiting with success';
58+
END
59+
-- If this is the preferred replica, continue to do the backup.
60+
/* actual backup command goes here */
61+
```
62+
63+
## Examples
64+
65+
### A. Use sys.fn_hadr_backup_is_preferred_replica
66+
67+
The following example returns 1 if the current database is the preferred backup replica.
68+
6069
```sql
61-
SELECT sys.fn_hadr_backup_is_preferred_replica ('TestDB');
62-
GO
63-
```
64-
65-
## <a name="RelatedTasks"></a> Related Tasks
66-
67-
- [Configure Backup on Availability Replicas &#40;SQL Server&#41;](../../database-engine/availability-groups/windows/configure-backup-on-availability-replicas-sql-server.md)
68-
69-
## See Also
70-
[Always On Availability Groups Functions &#40;Transact-SQL&#41;](../../relational-databases/system-functions/always-on-availability-groups-functions-transact-sql.md)
71-
[Always On Availability Groups &#40;SQL Server&#41;](../../database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server.md)
72-
[CREATE AVAILABILITY GROUP &#40;Transact-SQL&#41;](../../t-sql/statements/create-availability-group-transact-sql.md)
73-
[ALTER AVAILABILITY GROUP &#40;Transact-SQL&#41;](../../t-sql/statements/alter-availability-group-transact-sql.md)
74-
[Active Secondaries: Backup on Secondary Replicas &#40;Always On Availability Groups&#41;](../../database-engine/availability-groups/windows/active-secondaries-backup-on-secondary-replicas-always-on-availability-groups.md) [Always On Availability Groups Catalog Views &#40;Transact-SQL&#41;](../../relational-databases/system-catalog-views/always-on-availability-groups-catalog-views-transact-sql.md)
75-
76-
70+
SELECT sys.fn_hadr_backup_is_preferred_replica('TestDB');
71+
GO
72+
```
73+
74+
## Related tasks
75+
76+
- [Configure backups on secondary replicas of an Always On availability group](../../database-engine/availability-groups/windows/configure-backup-on-availability-replicas-sql-server.md)
77+
78+
## Related content
79+
80+
- [Always On Availability Groups Functions (Transact-SQL)](always-on-availability-groups-functions-transact-sql.md)
81+
- [What is an Always On availability group?](../../database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server.md)
82+
- [CREATE AVAILABILITY GROUP (Transact-SQL)](../../t-sql/statements/create-availability-group-transact-sql.md)
83+
- [ALTER AVAILABILITY GROUP (Transact-SQL)](../../t-sql/statements/alter-availability-group-transact-sql.md)
84+
- [Offload supported backups to secondary replicas of an availability group](../../database-engine/availability-groups/windows/active-secondaries-backup-on-secondary-replicas-always-on-availability-groups.md)
85+
- [Always On Availability Groups Catalog Views (Transact-SQL)](../system-catalog-views/always-on-availability-groups-catalog-views-transact-sql.md)

0 commit comments

Comments
 (0)