Edit

CREATE INDEX (Transact-SQL)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance Azure Synapse Analytics SQL database in Microsoft Fabric

Creates a relational index on a table or view. Also called a rowstore index because it is either a clustered or nonclustered B-tree index. You can create a rowstore index before there is data in the table. Use a rowstore index to improve query performance, especially when the queries select from specific columns or require values to be sorted in a particular order.

Note

Documentation uses the term B-tree generally in reference to indexes. In rowstore indexes, the Database Engine implements a B+ tree. This does not apply to columnstore indexes or indexes on memory-optimized tables. For more information, see the SQL Server and Azure SQL index architecture and design guide.

Azure Synapse Analytics currently doesn't support unique constraints. Any examples referencing unique constraints are only applicable to SQL Server, Azure SQL Database, SQL database in Microsoft Fabric, and Azure SQL Managed Instance.

For information on index design guidelines, refer to the SQL Server index design guide.

Examples:

  1. Create a nonclustered index on a table or view

    CREATE INDEX index1 ON schema1.table1 (column1);
    
  2. Create a clustered index on a table and use a 3-part name for the table

    CREATE CLUSTERED INDEX index1 ON database1.schema1.table1 (column1);
    
  3. Create a nonclustered index with a unique constraint and specify the sort order

    CREATE UNIQUE INDEX index1 ON schema1.table1 (column1 DESC, column2 ASC, column3 DESC);
    

Key scenario:

Starting with SQL Server 2016 (13.x), in Azure SQL Database, SQL database in Microsoft Fabric, and in Azure SQL Managed Instance, you can use a nonclustered index on a columnstore index to improve data warehousing query performance. For more information, see Columnstore indexes - data warehouse.

For additional types of indexes, see:

Transact-SQL syntax conventions

Syntax

Syntax for SQL Server, Azure SQL Database, SQL database in Fabric, Azure SQL Managed Instance

CREATE [ UNIQUE ] [ CLUSTERED | NONCLUSTERED ] INDEX index_name
    ON  ( column [ ASC | DESC ] [ ,...n ] )
    [ INCLUDE ( column_name [ ,...n ] ) ]
    [ WHERE  ]
    [ WITH (  [ ,...n ] ) ]
    [ ON { partition_scheme_name ( column_name )
         | filegroup_name
         | default
         }
    ]
    [ FILESTREAM_ON { filestream_filegroup_name | partition_scheme_name | "NULL" } ]

[ ; ]

 ::=
{ database_name.schema_name.table_or_view_name | schema_name.table_or_view_name | table_or_view_name }

 ::=
{
    PAD_INDEX = { ON | OFF }
  | FILLFACTOR = fillfactor
  | SORT_IN_TEMPDB = { ON | OFF }
  | IGNORE_DUP_KEY = { ON | OFF }
  | STATISTICS_NORECOMPUTE = { ON | OFF }
  | STATISTICS_INCREMENTAL = { ON | OFF }
  | DROP_EXISTING = { ON | OFF }
  | ONLINE = { ON [ (  ) ] | OFF }
  | RESUMABLE = { ON | OFF }
  | MAX_DURATION =