What if you could find any piece of data instantly, no matter how you search?
Primary vs secondary indexes in DBMS Theory - When to Use Which
Imagine you have a huge phone book with thousands of names and numbers. You want to find a friend's number quickly, but the book has no tabs or markers. You have to flip through every page until you find the name.
Searching manually is slow and tiring. If you want to find a number by name, you must check every entry. If you want to find a number by address, you have no easy way. This wastes time and causes mistakes.
Primary and secondary indexes act like organized tabs in the phone book. A primary index sorts entries by a main key, like name, so you find it fast. A secondary index lets you search by other keys, like address, without scanning everything.
search all records one by one for a valueuse primary index for main key search; use secondary index for other keys
Indexes let databases find data instantly using different keys, making searches fast and efficient.
When you search for a product on an online store by name, the primary index helps. When you filter by brand or price, secondary indexes speed up the results.
Primary index organizes data by main key for quick access.
Secondary index allows fast search on other attributes.
Both improve speed and reduce errors in data retrieval.