增加 varchar 字段大小时 SQL Server 2005 索引重建
我在大约 9000 万行的表中有 12 个 varchar(50) 字段,我需要将其长度增加到 varchar(100)。这些字段中的每一个都有一个索引(只有一个字段作为成员)。如果我增加 varchar 字段的长度,索引是否需要重建(或自动重建),或者统计信息是否会过时?
我没有合理规模的测试系统测试(或者可能不知道如何查看索引是否已重建或统计信息是否需要重新计算)。
谢谢
I have a 12 varchar(50) fields in a table of about 90 million rows that I need to increase to varchar(100) in length. Each of these fields has an index (with only the one field as a member). If I increase the length of the varchar fields, will the indexes either need to be rebuilt (or would be rebuilt automatically), or would the statistics become out of date?
I don't have a reasonably sized test system test (or perhaps dont know how to see if the indexes were rebuilt or statistics need to be recomputed).
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
统计数据基于列中的内容,而不是其大小,因此您的统计数据不会过时。
请记住,有时当您更改一列时,SQL Server 会向表中添加一新列并删除现有列,因此在这种情况下无论如何它都必须重建索引。
尽管进行了搜索,我不能明确地说是否必须重建索引,但无论如何我都会重建(因为这应该作为正常维护的一部分发生,假设该表不是只读或写入量非常低)
顺便说一句,有一个每个列上的单独索引可能不是最佳的。您是否分析过您的查询工作负载?
Statistics are based on what is in columns, not their size, so your statistics won't become out of date.
Bear in mind that sometimes when you alter a column, SQL server will add a new column to the table and drop the existing one, so it will have to rebuild the index in that case anyway.
Despite searching I can't categorically say whether you have to rebuild indexes, but I would rebuild regardless (as this should be occuring as part of your normal maintenance, assuming this table is not read-only or very low writes)
BTW, having a seperate index on each of those columns might not be optimal. Have you profiled your query workload?