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

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位图需要扩展)

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

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

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

我先说过先备用吗?

相关文章

SELECT a.*,b.dp_name,c.pa_name,fm_name=(CASE WHEN a.fm_n...
if not exists(select name from syscolumns where name=&am...
select a.*,pano=a.pa_no,b.pa_name,f.dp_name,e.fw_state_n...
要在 SQL Server 2019 中设置定时自动重启,可以使用 Window...
您收到的错误消息表明数据库 'EastRiver' 的...
首先我需要查询出需要使用SQL Server Profiler跟踪的数据库标...