Junior — Middle
How can an index be created for a database to speed up data searches?
sobes.tech AI
Answer from AI
To speed up data retrieval in a database, various types of indexes can be used:
- B-trees (B-Tree) — a standard index for fast search, sorting, and range queries.
- Hash indexes — effective for exact key lookups.
- Multi-column indexes (composite indexes) — accelerate queries filtering by multiple fields.
- Full-text indexes — for quick text searches.
In C#, when working with databases through ORM (e.g., Entity Framework), indexes are created at the database level using migrations or SQL queries. For example, creating an index in SQL:
CREATE INDEX IX_Table_Column ON Table(Column);
This allows the database to find records faster by the specified column.