创建身份列需要多长时间?

发布于 2024-08-03 00:29:11 字数 131 浏览 3 评论 0原文

我有一个包含 4000 万条记录的表。

什么是最好的(更快)?直接在该表中创建列,还是使用标识列创建另一个表并从第一个表插入数据?

如果我在有 4000 万条记录的表中创建一个标识列,是否可以估计创建它需要多长时间?

I have a table that have 40million records.

What's best (faster)? Create a column directly in that table or create another table with identity column and insert data from first?

If I create an identity column in the table that have 40million records, is it possible estimate how long does it take to create it?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

木槿暧夏七纪年 2024-08-10 00:29:11

这种要看情况。创建标识列不会花费那么长时间(好吧,这与表的大小有关),假设您将其附加到表的末尾。如果没有,服务器必须创建一个新表,并将标识列放在所需位置,将所有行导出到新表,然后更改表名称。我猜这就是花了这么长时间的原因。

This kind of depends. Creating an identity column won't take that long (well ok this is relative to the size of the table), assuming you appended it to the end of the table. If you didn't, the server has to create a new table with the identity column at the desired position, export all the rows to the new table, and then change the table name. I am guessing that is what is taking so long.

热情消退 2024-08-10 00:29:11

我猜它被阻止了 - 您是否使用了 GUI 或查询窗口(您知道它运行的 SPID 吗?)

尝试这些 - 让我们知道它们是否给出结果,而您不确定该怎么做:

USE master

SELECT * FROM sysprocesses WHERE blocked <> 0

SELECT * FROM sysprocesses WHERE status = 'runnable' AND spid <> @@SPID

I'm guessing it's blocked - did you use the GUI or a query window (do you know the SPID it's running under?)

Try these - let us know if they give results and you're not sure what to do:

USE master

SELECT * FROM sysprocesses WHERE blocked <> 0

SELECT * FROM sysprocesses WHERE status = 'runnable' AND spid <> @@SPID
天涯离梦残月幽梦 2024-08-10 00:29:11

如果您在查询窗口中使用ALTER TABLE [...] ADD ...,速度会非常快,事实上它早就完成了。如果您使用 Management Studio 表设计器,它会将表复制到新表中,删除旧表,然后将新表重命名为旧表。这将需要一段时间,特别是如果您没有预先增长数据库和日志来容纳所需的额外空间。因为都是一笔交易,如果现在停止的话,回滚还需要大约16个小时。

If you used ALTER TABLE [...] ADD ... in a query window, it is pretty fast, in fact it would have finished long ago. If you used the Management Studio table designer it is copying the table into a new table, dropping the old one, then renaming the new table as the old one. It will take a while, specially if you did not pre-grow the database and the log to accommodate the extra space needed. Because is all one single transaction, it would take about another 16 hours to rollback if you stop it now.

野の 2024-08-10 00:29:11

这不是你只需要做一次的事情吗,因此需要多长时间并不是真正的问题? (假设不需要几天...)

Isn't it something you'll only have to do once, and therefore isn't really a problem how long it takes? (Assuming it doesn't take days...)

德意的啸 2024-08-10 00:29:11

您不能创建数据库的测试副本并在其上创建列来查看需要多长时间吗?

Can you not create a test copy of the database and create the column on that to see how long it takes?

救赎№ 2024-08-10 00:29:11

我认为很大程度上取决于硬件以及您所在的 DBMS。在我的环境中,创建一个新表并将旧数据复制到其中大约需要 3 或 4 小时。根据其他经验,我预计添加身份列大约需要相同的时间。我使用的是在 SAN 上有多个服务器的 Oracle,因此运行速度比在单个服务器环境中更快。您可能只需要坐下来等待。

I think a lot depends upon the hardware and which DBMS you are in. In my environment, creating a new table and copying the old data into it would take about 3 or 4 hours. I would expect the addition of an identity column to take around the same amount of time, just based on other experiences. I'm on Oracle with multiple servers on a SAN, so things can run faster than in a single server environment. You may just have to sit back and wait.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文