SQL Server (2016) 将 INT 更改为 BIGINT

huangapple go评论67阅读模式
英文:

SQL Server (2016) Changing INT to BIGINT

问题

当将 INT 列更改为 BIGINT 列时,表中有超过 10 亿行时,是否仍然最佳做法是创建新表,然后迁移数据,或者在现今情况下使用 ALTER COLUMN 一样有效?

不太担心停机时间。

英文:

When changing an INT column to a BIGINT column on a table with over a 1 billion rows, is it still best practice to create a new table and then migrate the data, or is an ALTER COLUMN just as effective these days?

Not overly worried about downtime.

答案1

得分: 4

是否仍然是最佳实践创建新表然后迁移数据,

这只是在日志空间不足、阻塞过多或失败时回滚时间的情况下的一种权宜之计。所以如果你有足够的时间和资源,只需使用ALTER TABLE命令。

请注意,一旦开始执行ALTER TABLE命令,你就必须让它完成,否则如果取消它,可能需要很长时间来回滚。

批量加载新表可以很容易地中止,因为只需要回滚分配的范围。

英文:

>is it still best practice to create a new table and then migrate the data,

That's just a workaround for running out of log space, or excessive blocking, or rollback time in case of failure. So if you've got plenty of time and resources, just ALTER the table.

Just be aware that once you start the ALTER TABLE you're committed to let it finish or wait a possibly long time for it to roll back if you cancel it.

Bulk loading a new table can be aborted with little cost, as only the extent allocations need to be rolled back.

huangapple
  • 本文由 发表于 2023年6月22日 00:13:33
  • 转载请务必保留本文链接:https://go.coder-hub.com/76525269.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定