ALTER INDEX (Selective XML Indexes)

THIS TOPIC APPLIES TO:yesSQL Server (starting with 2012)yesAzure SQL DatabasenoAzure SQL Data Warehouse noParallel Data Warehouse

Modifies an existing selective XML index. The ALTER INDEX statement changes one or more of the following items:


ALTER INDEX index_name  
    ON <table_object>   
    [WITH XMLNAMESPACES ( <xmlnamespace_list> )]  
    FOR ( <promoted_node_path_action_list> )  
    [WITH ( <index_options> )]  

<table_object> ::=   
{ [database_name. [schema_name ] . | schema_name. ] table_name }  
<promoted_node_path_action_list> ::=   
<promoted_node_path_action_item> [, <promoted_node_path_action_list>]  

<add_node_path_item_action> | <remove_node_path_item_action>  

<add_node_path_item_action> ::=  
ADD <path_name> = <promoted_node_path_item>  

<xquery_node_path_item> | <sql_values_node_path_item>  

<remove_node_path_item_action> ::= REMOVE <path_name>   

<path_name> | <typed_node_path>  

<typed_node_path> ::=   
<node_path> [[AS XQUERY <xsd_type_ext>] | [AS SQL <sql_type>]]  

<xquery_node_path_item> ::=   
<node_path> [AS XQUERY <xsd_type_or_node_hint>] [SINGLETON]  

<xsd_type_or_node_hint> ::=   
[<xsd_type>] [MAXLENGTH(x)] | 'node()'  

<sql_values_node_path_item> ::=   
<node_path> AS SQL <sql_type> [SINGLETON]  

<node_path> ::=   

<xsd_type_ext> ::=   

<sql_type> ::=   

<path_name> ::=   

<xmlnamespace_list> ::=   
<xmlnamespace_item> [, <xmlnamespace_list>]  

<xmlnamespace_item> ::=   
<xmlnamespace_uri> AS <xmlnamespace_prefix>  

<xml_namespace_uri> ::= character_string_literal  
<xml_namespace_prefix> ::= identifier  

<index_options> ::=   
  | PAD_INDEX  = { ON | OFF }  
  | FILLFACTOR = fillfactor  
  | SORT_IN_TEMPDB = { ON | OFF }  
  | DROP_EXISTING = { ON | OFF }  
  | ALLOW_ROW_LOCKS = { ON | OFF }  
  | MAXDOP = max_degree_of_parallelism  


Is the name of the existing index to alter.

Is the table that contains the XML column to index. Use one of the following formats:

  • database_name.schema_name.table_name

  • database_name..table_name

  • schema_name.table_name

  • table_name

    Is the list of namespaces used by the paths to index. For information about the syntax of the WITH XMLNAMESPACES clause, see WITH XMLNAMESPACES (Transact-SQL).

    FOR ( )
    Is the list of indexed paths to add or remove.

  • ADD a path. When you ADD a path, you use the same syntax that is used to create paths with the CREATE SELECTIVE XML INDEX statement. For information about the paths that you can specify in the CREATE or ALTER statement, see Specify Paths and Optimization Hints for Selective XML Indexes.

  • REMOVE a path. When you REMOVE a path, you provide the name that was given to the path when it was created.

    [WITH ( )]
    You can only specify when you use ALTER INDEX without the FOR clause. When you use ALTER INDEX to add or remove paths in the index, the index options are not valid arguments. For information about the index options, see CREATE XML INDEX (Selective XML Indexes).



When you run an ALTER INDEX statement, the selective XML index is always rebuilt. Be sure to consider the impact of this process on server resources.



ALTER permission on the table or view is required to run ALTER INDEX.


The following example shows an ALTER INDEX statement. This statement adds the path '/a/b/m' to the XQuery part of the index and deletes the path '/a/b/e' from the SQL part of the index created in the example in the topic CREATE SELECTIVE XML INDEX (Transact-SQL). The path to delete is identified by the name that was given to it when it was created.

ALTER INDEX sxi_index  
ON Tbl  
    ADD pathm = '/a/b/m' as XQUERY 'node()' ,  
    REMOVE pathabe  

The following example shows an ALTER INDEX statement that specifies index options. Index options are permitted because the statement does not use a FOR clause to add or remove paths.

ALTER INDEX sxi_index  
ON Tbl  

See Also

Selective XML Indexes (SXI)
Create, Alter, and Drop Selective XML Indexes
Specify Paths and Optimization Hints for Selective XML Indexes