Which of the following statements is valid standard SQL to create an index (choose the only syntactically correct example)?

Difficulty: Easy

Correct Answer: CREATE INDEX idx_customer_name ON Customer(Name);

Explanation:

Introduction / Context:Indexes improve lookup performance by maintaining an additional data structure keyed by one or more columns. Creating an index requires specifying a name, a target table, and the indexed column list.

Given Data / Assumptions:

  • We want a valid, portable SQL example.
  • The example should follow the standard CREATE INDEX syntax.

Concept / Approach:The canonical form is: CREATE [UNIQUE] INDEX index_name ON table_name (column1[, column2 ...]);. Some DBMSs also support vendor-specific ALTER or DROP variants, but the creation syntax is widely consistent. Statements like CHANGE INDEX or REMOVE INDEX are not part of ANSI SQL.

Step-by-Step Solution:

Check each option against the required elements: command keyword, index name, target table, column list.Option A provides all components and proper ordering.Options B, C, D omit required parts and use non-standard verbs.

Verification / Alternative check:Vendor docs (PostgreSQL, SQL Server, Oracle, MySQL) all accept a CREATE INDEX statement with ON table(column). Minor dialect differences exist, but the structure is the same.

Why Other Options Are Wrong:CHANGE/ADD/REMOVE INDEX: Not standard creation syntax and missing table/column details; would fail in a compliant SQL engine.

Common Pitfalls:Forgetting the ON table(column) part; creating overlapping or redundant indexes that harm write performance; not analyzing selectivity before indexing.

Final Answer:CREATE INDEX idx_customer_name ON Customer(Name);

Discussion & Comments

No comments yet. Be the first to comment!
Join Discussion