Bird
0
0

What will be the outcome if the following SQL command is executed twice?

medium📝 query result Q5 of 15
SQL - Indexes and Query Performance
What will be the outcome if the following SQL command is executed twice?
CREATE INDEX idx_salary ON employees(salary);
AThe second execution will fail with an error about the index already existing.
BThe index will be created twice, improving performance further.
CThe second command will drop the first index and recreate it.
DThe database will ignore the second command silently.
Step-by-Step Solution
Solution:
  1. Step 1: Understand Index Creation Behavior

    Most SQL databases do not allow creating an index with the same name twice without dropping it first.
  2. Step 2: Analyze the Options

    The second execution will fail with an error about the index already existing. correctly states that the second attempt will cause an error. Options B, C, and D are incorrect behaviors.
  3. Final Answer:

    The second execution will fail with an error about the index already existing. -> Option A
  4. Quick Check:

    Duplicate index names cause errors [OK]
Quick Trick: Index names must be unique; duplicates cause errors [OK]
Common Mistakes:
  • Assuming indexes can be created multiple times with same name
  • Believing the second command silently succeeds
  • Thinking the index is automatically replaced

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SQL Quizzes