向具有超过 1500 万条记录的 SQL 列添加自动编号
我需要向 SQL 2005 中包含大约 1500 万条记录的现有表添加一个自动编号列。
您认为这需要多长时间?更好的方法是什么?
I need to add a autonumber column to an existing table which has about 15 million records in SQL 2005.
Do you think how much time it'll take? What's the better way to do it?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
确实很难说要花多长时间。
在我看来,最好的选择是带回生产数据库的副本,在开发环境中恢复它,并在那里应用您的更改,看看需要多长时间。
从那里,您可以协调站点停机时间,或安排更新在用户未连接时运行。
It's really difficult to say how long it will take.
In my opinion, your best bet would be to bring back a copy of the production database, restore it in a development environment, and apply your changes there to see how long it takes.
From there, you can coordinate site downtime, or schedule the update to run when users aren't connected.
除非是紧急情况:
要了解需要多少停机时间,请还原到新数据库并在其中进行更改。
它不应该很长:它不仅取决于有多少行,更取决于每行中有多少数据。 (SQL Server 将复制整个表。)
Unless it's an emergency:
To find out how much downtime you'll need, do a restore to a new DB and make the change there.
It shouldn't be very long: it depends not only on how many rows, but even more on how much data there is in each row. (SQL Server is going to copy the entire table over.)
您是否可以选择备份生产数据库、在另一台服务器上应用更改并更改连接字符串?您甚至可以将其恢复到与原始服务器相同的服务器上,更改连接字符串并删除旧数据库。
如果磁盘空间有限,则可能不可行。
Do you have the option of backing up the production database, applying the changes on another server and changing connection strings? You could even restore it on the same server as the original, change connection strings and get rid of the old database.
May not be feasible if disk space is limited.
为了最大限度地减少影响,我将创建一个添加了标识列的新表,通过从旧表中进行选择来插入到新表中,然后删除旧表并重命名新表。下面我将给出一个基本的轮廓。可能需要额外的步骤来处理外键等。
To minimize impact, I would create a new table with the identity column added, insert into the new table by selecting from the old table, then drop the old table and rename the new. I'll give a basic outline below. Extra steps may be needed to handle foreign keys, etc.