Which statement creates an index on orders(customer_id) with the name idx_orders_customer_id?

Study for the SQL Basics Test. Improve your knowledge with multiple choice questions and detailed explanations. Prepare effectively to master SQL concepts!

Multiple Choice

Which statement creates an index on orders(customer_id) with the name idx_orders_customer_id?

Explanation:
Creating a named non‑unique index on a table uses the pattern: CREATE INDEX index_name ON table_name (column_list). Here, the index name is provided as idx_orders_customer_id, the target table is orders, and the column to index is customer_id. This exactly matches the requirement to create an index on orders(customer_id) with that name, and it yields a standard non-unique index suitable for lookups by customer_id. If you used UNIQUE, you’d enforce that each customer_id appears only once in orders, which would prevent multiple orders for the same customer—usually not desired. If you omit the index name, many systems require a name. If you point to a different table, like customers, you’d be indexing the wrong table.

Creating a named non‑unique index on a table uses the pattern: CREATE INDEX index_name ON table_name (column_list). Here, the index name is provided as idx_orders_customer_id, the target table is orders, and the column to index is customer_id. This exactly matches the requirement to create an index on orders(customer_id) with that name, and it yields a standard non-unique index suitable for lookups by customer_id.

If you used UNIQUE, you’d enforce that each customer_id appears only once in orders, which would prevent multiple orders for the same customer—usually not desired. If you omit the index name, many systems require a name. If you point to a different table, like customers, you’d be indexing the wrong table.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy