0

I learned that I can index a column like this :

CREATE INDEX idx_lastname
ON Persons (LastName);

The source also says that I can index a combination of indexes like this :

CREATE INDEX idx_pname
ON Persons (LastName, FirstName);

I want to know what happens if I add FirstName? In what way will the searching in the db be faster? What will happen if I index FirstName and LastName seperately? Thanks.

jason
  • 6,962
  • 36
  • 117
  • 198
  • Did you at least google *multi column index*? – juergen d Jun 26 '17 at 14:34
  • 2
    engine can only use 1 index. so if you have lots of persons who have the same last name, and you're joining or searching on last name with first name, the index will be more efficient than if it could just use the last name or first name index. However, if a LAST name isn't provided, then it can't use the lastname, first name index. and one with JUST first name COULD be used. So why wouldn't you just index everything? because there's a space and insert/update cost to maintaining the index. https://stackoverflow.com/questions/179085/multiple-indexes-vs-multi-column-indexes – xQbert Jun 26 '17 at 14:36
  • http://use-the-index-luke.com/ –  Jun 26 '17 at 14:58

0 Answers0