I'm working on a system backed up by a rather large SQL Server 2008 database, about 250 tables. After doing some performance optimization, I discovered that in many of the tables there were missing indexes on the foreign keys. After going through all the tables in more details, I identified about 150 foreign keys with potential missing indexes.
I know that it is generally good practice to put an index on every foreign key, and I also know that indexes aren't automatically created for foreign keys. I suspect that people not thinking about (or being aware of...) the latter is the reason why the database has ended up in its current condition.
But since I'm not even close to an expert on database optimization, I thought I'd fire away a control question before starting to add all those indexes:
Question:
Are there any special considerations to keep in mind when adding such a large number of indexes to an existing database?
The only thing I can think of myself, is that for every index you can get a potential performance penalty for inserts and updates. But for indexes strictly on foreign key columns, I picture that that's not a major problem. Also, our database isn't really insert/update intensive, another reason for that not being an issue.
I could perhaps also mention that we use NHibernate as our ORM layer, which I guess is yet another reason for having good indexes on foreign keys (since we're accessing lots of objects through foreign key properties).