Skip to content

Commit 07c0935

Browse files
authored
Update hints-transact-sql-table.md
1 parent 0519d78 commit 07c0935

1 file changed

Lines changed: 18 additions & 19 deletions

File tree

docs/t-sql/queries/hints-transact-sql-table.md

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,9 @@ ms.author: vanto
6666
WITH ( <table_hint> [ [, ]...n ] )
6767
6868
<table_hint> ::=
69-
[ NOEXPAND ] {
70-
INDEX ( index_value [ ,...n ] )
71-
| INDEX = ( index_value )
72-
| FORCESEEK [( index_value ( index_column_name [ ,... ] ) ) ]
69+
{ NOEXPAND [ , INDEX ( <index_value> [ ,...n ] ) | INDEX = ( <index_value> ) ]
70+
| INDEX ( <index_value> [ ,...n ] ) | INDEX = ( <index_value> )
71+
| FORCESEEK [ ( <index_value> ( <index_column_name> [,... ] ) ) ]
7372
| FORCESCAN
7473
| FORCESEEK
7574
| HOLDLOCK
@@ -84,7 +83,7 @@ WITH ( <table_hint> [ [, ]...n ] )
8483
| ROWLOCK
8584
| SERIALIZABLE
8685
| SNAPSHOT
87-
| SPATIAL_WINDOW_MAX_CELLS = integer
86+
| SPATIAL_WINDOW_MAX_CELLS = <integer_value>
8887
| TABLOCK
8988
| TABLOCKX
9089
| UPDLOCK
@@ -139,15 +138,15 @@ FROM t WITH (TABLOCK, INDEX(myindex))
139138
We recommend using commas between table hints.
140139

141140
> [!IMPORTANT]
142-
> Separating hints by spaces rather than commas is a deprecated feature: [!INCLUDE[ssNoteDepFutureDontUse](../../includes/ssnotedepfuturedontuse-md.md)]
141+
> Separating hints by spaces rather than commas is a deprecated feature: [!INCLUDE[ssNoteDepFutureDontUse](../../includes/ssnotedepfuturedontuse-md.md)]
143142
144143
NOEXPAND
145144
Specifies that any indexed views are not expanded to access underlying tables when the query optimizer processes the query. The query optimizer treats the view like a table with clustered index. NOEXPAND applies only to indexed views. For more information, see [Using NOEXPAND](#using-noexpand).
146145

147-
INDEX **(**_index\_value_ [**,**... _n_ ] ) | INDEX = ( _index\_value_**)**
148-
The INDEX() syntax specifies the names or IDs of one or more indexes to be used by the query optimizer when it processes the statement. The alternative INDEX = syntax specifies a single index value. Only one index hint per table can be specified.
146+
INDEX **(**_<index\_value>_ [**,**... _n_ ] ) | INDEX = ( _<index\_value>_**)**
147+
The INDEX() syntax specifies the names or IDs of one or more indexes to be used by the query optimizer when it processes the statement. The alternative `INDEX =` syntax specifies a single index value. Only one index hint per table can be specified.
149148

150-
If a clustered index exists, INDEX(0) forces a clustered index scan and INDEX(1) forces a clustered index scan or seek. If no clustered index exists, INDEX(0) forces a table scan and INDEX(1) is interpreted as an error.
149+
If a clustered index exists, `INDEX(0)` forces a clustered index scan and `INDEX(1)` forces a clustered index scan or seek. If no clustered index exists, `INDEX(0)` forces a table scan and `INDEX(1)` is interpreted as an error.
151150

152151
If multiple indexes are used in a single hint list, the duplicates are ignored and the rest of the listed indexes are used to retrieve the rows of the table. The order of the indexes in the index hint is significant. A multiple index hint also enforces index ANDing, and the query optimizer applies as many conditions as possible on each index accessed. If the collection of hinted indexes do not include all columns referenced by the query, a fetch is performed to retrieve the remaining columns after the [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] retrieves all the indexed columns.
153152

@@ -175,7 +174,7 @@ Specifies insertion of a table column's default value, if any, instead of NULL w
175174

176175
For an example that uses this hint in an INSERT ... SELECT * FROM OPENROWSET(BULK...) statement, see [Keep Nulls or Use Default Values During Bulk Import &#40;SQL Server&#41;](../../relational-databases/import-export/keep-nulls-or-use-default-values-during-bulk-import-sql-server.md).
177176

178-
FORCESEEK [ **(**_index\_value_**(**_index\_column\_name_ [ **,**... _n_ ] **))** ]
177+
FORCESEEK [ **(**_<index\_value>_**(**_<index\_column\_name>_ [ **,**... _n_ ] **))** ]
179178
Specifies that the query optimizer use only an index seek operation as the access path to the data in the table or view.
180179

181180
> [!NOTE]
@@ -229,7 +228,7 @@ For partitioned tables and indexes, FORCESCAN is applied after partitions have b
229228
The FORCESCAN hint has the following restrictions:
230229
- The hint cannot be specified for a table that is the target of an INSERT, UPDATE, or DELETE statement.
231230
- The hint cannot be used with more than one index hint.
232-
- The hint prevents the optimizer from considering any spatial or XML indexes on the table.
231+
- The hint prevents the Query Optimizer from considering any spatial or XML indexes on the table.
233232
- The hint cannot be specified for a remote data source.
234233
- The hint cannot be specified in combination with the FORCESEEK hint.
235234

@@ -326,9 +325,9 @@ LEFT JOIN dbo.[Order History] AS oh
326325
ON c.customer_id=oh.customer_id;
327326
```
328327

329-
SPATIAL_WINDOW_MAX_CELLS = *integer*
328+
SPATIAL_WINDOW_MAX_CELLS = *<integer\_value>*
330329
**Applies to**: [!INCLUDE[ssSQL11](../../includes/sssql11-md.md)] and later.
331-
Specifies the maximum number of cells to use for tessellating a geometry or geography object. *number* is a value between 1 and 8192.
330+
Specifies the maximum number of cells to use for tessellating a geometry or geography object. *<integer\_value>* is a value between 1 and 8192.
332331

333332
This option allows for fine-tuning of query execution time by adjusting the tradeoff between primary and secondary filter execution time. A larger number reduces secondary filter execution time, but increases primary execution filter time and a smaller number decreases primary filter execution time, but increase secondary filter execution. For denser spatial data, a higher number should produce a faster execution time by giving a better approximation with the primary filter and reducing secondary filter execution time. For sparser data, a lower number will decrease the primary filter execution time.
334333

@@ -385,12 +384,12 @@ SELECT StartDate, ComponentID FROM Production.BillOfMaterials
385384
GO
386385
```
387386

388-
The query optimizer will not consider an index hint if the SET options do not have the required values for filtered indexes. For more information, see [CREATE INDEX &#40;Transact-SQL&#41;](../../t-sql/statements/create-index-transact-sql.md).
387+
The Query Optimizer will not consider an index hint if the SET options do not have the required values for filtered indexes. For more information, see [CREATE INDEX &#40;Transact-SQL&#41;](../../t-sql/statements/create-index-transact-sql.md).
389388

390389
## Using NOEXPAND
391-
NOEXPAND applies only to *indexed views*. An indexed view is a view with a unique clustered index created on it. If a query contains references to columns that are present both in an indexed view and base tables, and the query optimizer determines that using the indexed view provides the best method for executing the query, the query optimizer uses the index on the view. This functionality is called *indexed view matching*. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql15-md.md)] SP1, automatic use of an indexed view by the query optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. For a list of features that are supported by the editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], see [Features Supported by the Editions of SQL Server 2016](../../sql-server/editions-and-supported-features-for-sql-server-2016.md).
390+
NOEXPAND applies only to *indexed views*. An indexed view is a view with a unique clustered index created on it. If a query contains references to columns that are present both in an indexed view and base tables, and the query optimizer determines that using the indexed view provides the best method for executing the query, the query optimizer uses the index on the view. This functionality is called *indexed view matching*. Prior to [!INCLUDE[ssSQL15_md](../../includes/sssql15-md.md)] SP1, automatic use of an indexed view by the Query Optimizer is supported only in specific editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)]. For a list of features that are supported by the editions of [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)], see [Features Supported by the Editions of SQL Server 2016](../../sql-server/editions-and-supported-features-for-sql-server-2016.md), [Features Supported by the Editions of SQL Server 2017](../../SQL-server/editions-and-components-of-SQL-server-2017.md), and [Features Supported by the Editions of SQL Server 2019](../../sql-server/editions-and-components-of-sql-server-version-15.md).
392391

393-
However, for the optimizer to consider indexed views for matching, or use an indexed view that is referenced with the NOEXPAND hint, the following SET options must be set to ON.
392+
However, for the Query Optimizer to consider indexed views for matching, or use an indexed view that is referenced with the NOEXPAND hint, the following SET options must be set to ON.
394393

395394
> [!NOTE]
396395
> [!INCLUDE[ssSDSfull](../../includes/sssdsfull-md.md)] supports automatic use of indexed views without specifying the NOEXPAND hint.
@@ -406,14 +405,14 @@ However, for the optimizer to consider indexed views for matching, or use an ind
406405

407406
Also, the NUMERIC_ROUNDABORT option must be set to OFF.
408407

409-
To force the optimizer to use an index for an indexed view, specify the NOEXPAND option. This hint can be used only if the view is also named in the query. [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] does not provide a hint to force a particular indexed view to be used in a query that does not name the view directly in the FROM clause; however, the query optimizer considers using indexed views, even if they are not referenced directly in the query. SQL Server will only automatically create statistics on an indexed view when a NOEXPAND table hint is used. Omitting this hint can lead to execution plan warnings about missing statistics that cannot be resolved by creating statistics manually.
410-
During query optimization [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] will use view statistics that were created automatically or manually when the query references the view directly and the NOEXPAND hint is used.
408+
To force the Query Optimizer to use an index for an indexed view, specify the NOEXPAND option. This hint can be used only if the view is also named in the query. [!INCLUDE[ssNoVersion](../../includes/ssnoversion-md.md)] does not provide a hint to force a particular indexed view to be used in a query that does not name the view directly in the FROM clause; however, the Query Optimizer considers using indexed views, even if they are not referenced directly in the query. The [!INCLUDE[ssDEnoversion](../../includes/ssdenoversion-md.md)] will only automatically create statistics on an indexed view when a NOEXPAND table hint is used. Omitting this hint can lead to execution plan warnings about missing statistics that cannot be resolved by creating statistics manually.
409+
During query optimization, the [!INCLUDE[ssde_md](../../includes/ssde_md.md)] will use view statistics that were created automatically or manually when the query references the view directly and the NOEXPAND hint is used.
411410

412411
## Using a Table Hint as a Query Hint
413412
*Table hints* can also be specified as a query hint by using the OPTION (TABLE HINT) clause. We recommend using a table hint as a query hint only in the context of a [plan guide](../../relational-databases/performance/plan-guides.md). For ad-hoc queries, specify these hints only as table hints. For more information, see [Query Hints &#40;Transact-SQL&#41;](../../t-sql/queries/hints-transact-sql-query.md).
414413

415414
## Permissions
416-
The KEEPIDENTITY, IGNORE_CONSTRAINTS, and IGNORE_TRIGGERS hints require ALTER permissions on the table.
415+
The KEEPIDENTITY, IGNORE_CONSTRAINTS, and IGNORE_TRIGGERS hints require `ALTER` permissions on the table.
417416

418417
## Examples
419418

0 commit comments

Comments
 (0)