开发者

Adding Index on every foreign key - Pros and Cons?

We have an SQL Server 2008 R2 database that is attached to our web application. Data is added each day, but MANY reports are run against it. As such the data is being read much more often than it is being written to.

The reports are running slow, and adding the 'suggested indexes' has helped, but I think just adding every foreign key will help the most overall.

Are there any downside? We already run a full maintenance on a Saturday (rebuilds indexes etc). so that's not a problem.

OR, would it be best to only add indexes for all Fkeys on all tables with OVER X Rows, where x is 1000?

Any help appreciated!

PS, the biggest table has only 570288 rows in, the next biggest 273255. 188 tables in all, but only 开发者_运维问答32 of them have more than 1000 rows!


The ones with less than 1000 rows probaly won't benefit much from the index especially if both the parent and child tables are small. SQL Server is likely to to a full table scan no matter what. In that case you are probaly just adding over head on insert by adding the index. Most of the time, large table should have indexes on FK fields unless they will rarely be used in a join due to denormalization.

In your case I would probably put the indexes on for the large tables (or ones you expect to get large) and leave them be on a the small tables and see if performance improves. Then if you still have some slow running queries, look at them on an individual basis.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜