如何索引MS SQL中的所有外键? [英] How to index all foreign keys in MS SQL?

查看:116
本文介绍了如何索引MS SQL中的所有外键?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有大量的MS SQL数据库,有很多表和外键。我们需要索引表中的所有外键,因此我们试图避免手动完成。有没有办法让MS SQL自动或使用一些工具?



使用的MS SQL服务器是MS SQL Server 2008 R2。

非常感谢。

解决方案

我试图避免尝试自动执行此操作,并鼓励您检查您的系统(Google缺少索引DMV(SQL 2005或更高版本)为了一个好的开始),并创建适当的索引。如果您尝试自动执行此操作,则可能会引入以下问题:


  • 在低
    的列上创建索引基数将消耗资源,但永远不会被使用
    (例如,一个外键到一个查找
    表中有少量可能的值)

  • 介绍书签查找是因为您创建的索引
    可能包含额外的
    列,从而获得
    的收益。

  • b

    我并不是说你的外键不应该被编入索引,只是在创建这些索引时应该有一些想法。


    We have large MS SQL database with many tables and foreign keys. We need to index all foreign keys in our tables due to performances and we are trying to avoid do it manually. Is there any way to MS SQL do it automatically or with some tools?

    MS SQL server used is MS SQL Server 2008 R2.

    Thanks a lot.

    解决方案

    I'd steer you away from trying to do this automatically and encourage you to examine your system (Google missing index DMVs (SQL 2005 or later) for a good start) and create appropriate indexes instead. If you try to do this automatically, you could potentially introduce issues like:

    • Creating indexes on columns with low cardinality that will consume resources but never be used (e.g., a foreign key to a lookup table with a small number of possible values)

    • Introducing bookmark lookups because the indexes you created could have benefited from including additional columns.

    I'm not saying your foreign keys should not be indexed, just that there should be some thought put into the creation of those indexes.

    这篇关于如何索引MS SQL中的所有外键?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆