降低PK对其他指标的影响
我需要更新大型 SQL Server 2005 数据库中的大量键,并且将在一堆表上删除 FK 和 PK,进行更新(替换 PK/FK 的值),然后添加 FK 和 PK再次。
我的问题是:
此过程是否会对这些表上现有的索引产生任何影响 包含 PK/FK 字段的索引或其他不受影响字段的索引。即所有索引仍然存在,它们需要重建
此过程是否会影响表统计信息,需要重新计算?
非常感谢
I need to update a large number of keys in a large SQL Server 2005 database and will be dropping FKs and PKs on a bunch of tables, doing the update (which replaces the values of the PK/FK) and then adding the FK and PK again.
My questions are:
Will this process have any effect on exsiting indexes that exist on those tables, either
indexes that include the PK/FK fields or indexes on other unaffected fields. ie will all indexes still exists, will they need a rebuild?Will this process affect table statistics, requiring a recalc?
Many thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您删除 PK(通常是聚集索引),SQL Server 将删除并重新创建所有非聚集索引(这是必需的,因为如果您有聚集索引,非聚集索引将指向聚集索引)。如果您没有聚集索引(堆),则非聚集索引指向数据行
重建聚集索引将自动更新统计信息,重组不会
如果您使用
级联更新 然后它们应该自动更新
例如
现在更新 PK 表,
现在也将是 5
If you drop a PK (which is usually a clustered index) SQL Server will drop and recreate all non clustered indexes(this is needed because if you have a clustered index the non clustered indexes point to the clustered index). If you don't have a clustered index (a heap) the non clustered indexes point to the data row
rebuilding a clustered index will automatically update statistics, a reorg won't
If you created the keys with
cascade update
then they should be updated automaticallyexample
now update the PK table
this will now be 5 also
索引列的每次更改都会导致结构更改的传播。
对于外键,您可以禁用它们然后重建。对于私钥,您唯一能做的就是重建它们。我认为 SQLMenace 清楚地解释了原因。
更多
Every change in indexed column has a propagation in structure change.
For foreign key you could disable them and then rebuild. For private key only thing you can do is to rebuild them. I think that SQLMenace explained it clearly why.
More