0
0
Ruby on Railsframework~5 mins

Index creation in Ruby on Rails - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
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?
Aadd_column :users, :email_index
Bcreate_index :users, :email
Cadd_index :users, :email
Dindex_add :users, :email
What is the main benefit of adding an index to a database column?
AFaster data retrieval
BMore storage space
CSlower queries
DAutomatic backups
What is a potential downside of having too many indexes?
ASlower data insertion and updates
BFaster data insertion
CNo effect on performance
DDatabase crashes
How do you enforce uniqueness of values in a column using an index in Rails?
Aadd_unique_index :table, :column
Badd_index :table, :column, unique: true
Cadd_index :table, :column, unique: false
Dcreate_unique :table, :column
Which command removes an index on the 'username' column in the 'accounts' table?
Adrop_index :accounts, :username
Bremove_column :accounts, :username
Cdelete_index :accounts, :username
Dremove_index :accounts, :username
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.