The above query will create NONCLUSTER INDEX ON OrderDetails table and add the OrderName, OrderAddress, OrderDate and select the columnName OrderName, orderAddress, OrderDate from OrderDetails Table and Where statement OrderId Between 8 To 10.
How to Create a partitioned index statement
The following example creates a nonclustered partitioned index on Product_Details, an existing partition scheme in the sample database. This example assumes the partitioned index sample has been installed.
Syntax
- CREATE NONCLUSTERED INDEX Product_Details
- ON OrderDetails (OrderId)
- GO
How to create a filtered index statement
The following example creates a filtered index on the OrderDetails table in the sample database. The filter predicate can include columns that are not key columns in the filtered index. The predicate in this example selects only the rows where EndDate is non-NULL.
Syntax
- CREATE NONCLUSTERED INDEX Product_List
- ON OrderDetails (OrderId, OrderName, OrderAddress)
- WHERE OrderDate IS NOT NULL;
How to create a compressed index statement
The following example creates an index on a nonpartitioned table by using row compression.
Syntax
- CREATE NONCLUSTERED INDEX ProductDetails
- ON OrderDetails (OrderName)
- WITH (DATA_COMPRESSION = ROW);
- GO
The following example creates an index on a partitioned table by using row compression on all partitions of the index.
Syntax
- CREATE CLUSTERED INDEX Product_Details
- ON OrderDetails (OrderId)
- WITH (DATA_COMPRESSION = ROW);
- GO
The following example creates an index on a partitioned table by using page compression on partition 1 of the index and row compression on partitions 2 through 4 of the index.
Syntax
- CREATE CLUSTERED INDEX Product_Details
- ON OrderDetails (OrderId)
- WITH (
- DATA_COMPRESSION = PAGE ON PARTITIONS(1),
- DATA_COMPRESSION = ROW ON PARTITIONS (2 TO 4)
- );
- GO
Create, resume, pause, and abort resumable index operations
Syntax
-
- CREATE INDEX OrderId ON OrderDetails (OrderId) WITH (ONLINE = ON, MAXDOP = 1, RESUMABLE = ON);
-
-
-
-
- CREATE INDEX OrderId ON EmployeeDetail (EmpName) WITH (ONLINE = ON, RESUMABLE = ON, MAX_DURATION = 240);
-
-
- ALTER INDEX EmpId ON employeDetail PAUSE;
- ALTER INDEX EmpName ON EmployeeDetail PAUSE;
-
-
- ALTER INDEX EmpId ON employeDetail RESUME;
- ALTER INDEX EmpName ON EmployeeDetail RESUME;
-
-
- ALTER INDEX EmpId ON employeDetail ABORT;
- ALTER INDEX EmpName ON EmployeeDetail ABORT;
The above query will create Index OrderId from EmployeeDetail table name from EmpName with Online=on, Resumable= on, MAX_DURATION=240 And the ALTER INDEX to add column name EmpId, EmpName on EmployeeDetail Table name PAUSE, RESUME, ABORT statement.
How to create a nonclustered index on a table in the current database
The following example creates a nonclustered index on the OrderId column of the OrderDetails table.
Syntax
- CREATE INDEX OrderName
- ON OrderDetails (OrderID);
How to create a clustered index on a table in another database
The following example creates a nonclustered index on the OrderId column of the OrderDetails table.
Syntax
- CREATE INDEX NewOrderDetails
- ON OrderDetails(OrderId);
How to create a clustered index on a table in another database
The following example creates a nonclustered index on the OrderName column of the OrderDetails table.
Syntax
- CREATE CLUSTERED INDEX Order_Id
- ON OrderDetail (OrerName);
Summary
In this article, you learned how to use a SQL Create Index statement with various options.