Welcome Back

Google icon Sign in with Google
OR
I agree to abide by Pharmadaily Terms of Service and its Privacy Policy

Create Account

Google icon Sign up with Google
OR
By signing up, you agree to our Terms of Service and Privacy Policy
Instagram
youtube
Facebook

Create a Composite Index on OrderDetails(OrderID, ProductID)

Create a Composite Index on OrderDetails(OrderID, ProductID)

Short Description:

  • Purpose: Improves the performance of queries that filter, sort, or join based on both OrderID and ProductID columns.

  • Composite Index: An index created on multiple columns (in this case, OrderID and ProductID), which is particularly useful when queries involve both columns simultaneously.

  • CREATE INDEX: Defines an index for faster data access.

  • idx_OrderDetails_OrderID_ProductID: Custom name for the index (can be renamed as needed).

  • Usage Benefit: Optimizes queries like:
     

SQL Query:

CREATE INDEX idx_OrderDetails_OrderID_ProductID
ON OrderDetails(OrderID, ProductID);

Then:
SELECT * FROM OrderDetails WHERE OrderID = 1 AND ProductID = 1;

Output: