You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
|**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). |
39
40
40
41
## 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).
42
42
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.
|**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).|
[Query Store Stored Procedures (Transact-SQL)](../../relational-databases/system-stored-procedures/query-store-stored-procedures-transact-sql.md)
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.
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
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
48
56
-- 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.
-[Configure Backup on Availability Replicas (SQL Server)](../../database-engine/availability-groups/windows/configure-backup-on-availability-replicas-sql-server.md)
68
-
69
-
## See Also
70
-
[Always On Availability Groups Functions (Transact-SQL)](../../relational-databases/system-functions/always-on-availability-groups-functions-transact-sql.md)
71
-
[Always On Availability Groups (SQL Server)](../../database-engine/availability-groups/windows/overview-of-always-on-availability-groups-sql-server.md)
72
-
[CREATE AVAILABILITY GROUP (Transact-SQL)](../../t-sql/statements/create-availability-group-transact-sql.md)
73
-
[ALTER AVAILABILITY GROUP (Transact-SQL)](../../t-sql/statements/alter-availability-group-transact-sql.md)
74
-
[Active Secondaries: Backup on Secondary Replicas (Always On Availability Groups)](../../database-engine/availability-groups/windows/active-secondaries-backup-on-secondary-replicas-always-on-availability-groups.md)[Always On Availability Groups Catalog Views (Transact-SQL)](../../relational-databases/system-catalog-views/always-on-availability-groups-catalog-views-transact-sql.md)
-[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