Recall & Review
beginner
What is an index in a database?
An index is like a shortcut that helps the database find data faster, similar to an index in a book that points to pages quickly.
Click to reveal answer
beginner
How do you create an index on a column in Rails migrations?
You use
add_index :table_name, :column_name inside a migration file to create an index on that column.Click to reveal answer
intermediate
Why should you use indexes carefully?
Indexes speed up reading data but slow down writing data because the index needs updating. So, use them only on columns you search often.
Click to reveal answer
intermediate
What does a unique index do?
A unique index makes sure that all values in the indexed column are different, preventing duplicate entries.
Click to reveal answer
beginner
How do you remove an index in Rails?
You use
remove_index :table_name, :column_name in a migration to delete an index.Click to reveal answer
Which Rails migration command creates an index on the 'email' column of the 'users' table?
✗ Incorrect
The correct syntax to add an index is
add_index :table_name, :column_name.What is the main benefit of adding an index to a database column?
✗ Incorrect
Indexes help the database find data faster, improving query speed.
What is a potential downside of having too many indexes?
✗ Incorrect
Indexes need updating when data changes, which can slow down insert and update operations.
How do you enforce uniqueness of values in a column using an index in Rails?
✗ Incorrect
You add
unique: true option to add_index to enforce uniqueness.Which command removes an index on the 'username' column in the 'accounts' table?
✗ Incorrect
The correct command to remove an index is
remove_index :table_name, :column_name.Explain what a database index is and why it is useful.
Think about how you find a topic quickly in a book.
You got /3 concepts.
Describe how to create and remove an index in Rails migrations.
Use Rails migration commands for managing indexes.
You got /3 concepts.