加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MsSql教程 > 正文

sql-server – 将列添加到生产表

发布时间:2020-12-12 06:20:34 所属栏目:MsSql教程 来源:网络整理
导读:在SQL Server 2008 R2上向大型生产表添加列的最佳方法是什么?根据微软的在线书籍: The changes specified in ALTER TABLE are implemented immediately. If the changes require modifications of the rows in the table,ALTER TABLE updates the rows. ALT
在SQL Server 2008 R2上向大型生产表添加列的最佳方法是什么?根据微软的在线书籍:

The changes specified in ALTER TABLE are implemented immediately. If the changes require modifications of the rows in the table,ALTER TABLE updates the rows. ALTER TABLE acquires a schema modify lock on the table to make sure that no other connections reference even the metadata for the table during the change,except online index operations that require a very short SCH-M lock at the end.

(http://msdn.microsoft.com/en-us/library/ms190273.aspx)

在具有数百万行的大型表上,这可能需要一段时间.停电是唯一的选择吗?处理这种情况的最佳方法是什么?

解决方法

“这取决于”

如果添加不需要向行添加数据的列,则可以非常快.

例如,添加int或char需要物理行移动.添加一个没有默认值的可空varchar不应该(除非NULL位图需要扩展)

您需要在已恢复的生产副本上进行尝试才能获得估算值

如果必须在十亿行表上重新添加索引和键,则创建新表,复制,重命名可能需要更长时间.

我已经改变了十亿行表,花了几秒钟来添加一个可以为空的列.

我先说过先备用吗?

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读