views:

61

answers:

1

I've got a table with approx 7 million rows of data. The schema is something like:

ID  - int (Primary Key)
Name - Varchar(250) Null
...

I want to set an index up for the Name column to speed up searches. e.g

Select * from table where name = 'ABC'

But what is the impact of setting up an Index on a varchar field? Index size? Does the speed benfit outweigh the cons?

A: 

If you have to search by this field often, there's no question - you need an index on it. The insertion will be a tiny bit slower, and you'll lose several MBs in your hard drive, but it's nothing compared to the look-up time you'll waive when searching for a value in this field.

Roee Adler
A side question: Would a like search benefit from this index? e.g select * from table where name like '%abc%'
A "abc%" search will definitely benefit. Regarding "%abc%" the effect is minimal. If it's a common scenario in your application (and the tables are large or the fields are large) - you have "Full Text Search" as an alternative to simple indexing.
Roee Adler