批量更新大表
我有一个包含 26 列和几千条记录的表。 有没有办法批量更新这个表?
现在我只是对每个需要更新的列进行标准更新。 例如,
update mytbl
set col1 = replace(....)
update mytbl
set col1 = col1 + "xyz"
update mytbl
set col2 = "test..."
我知道对于每条记录,上面的语句将首先更新所有记录的列,然后再转到下一列。
我正在寻找“快速批量更新”,因为这花费的时间太长。
谢谢
I have a table that has 26 columns with a couple of thousand records.
Is there a way to bulk update this table?
Right now I just do a standard update on each column that needs updating.
E.g.
update mytbl
set col1 = replace(....)
update mytbl
set col1 = col1 + "xyz"
update mytbl
set col2 = "test..."
I know that for each record the statements above will update the column for all records first before going to next column(s).
I'm looking for a "quick bulk update" as this is taking too long.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您可以使用此结构:
You can use this structure:
1 - 几千条记录 x 26 个字段并不大:)
2 - 使用 ck 建议的多字段更新语法,或者将其插入到可能更快的新表中:
1 - A couple thousand records x 26 fields isn't huge :)
2 - Either use the multiple-field update syntax ck suggests, or insert it into a new table which may be faster:
这些建议对于大量记录更有用,但无论如何可能会有所帮助:
1. 按照 ck
的建议使用多字段更新如果可以在更新期间锁定表以进行独占访问。
禁用所有索引。更新完成后恢复它们。
These advices are more useful for much bigger number of records, but might help anyway:
1. Use multifield update as suggested by ck
If it is possible lock the table for exclusive access during the update.
Disable all of the indexes. Restore them after update finished.
请注意以下几点。
您可以使用 SQL Profiler 来检查更新过程中是否有任何触发器正在执行某些操作。
您可以禁用索引。现在运行您的测试并最终恢复它。
Please take care of following points.
You can use SQL Profiler to to check that whether any trigger is doing something during your updation process.
You can disable the indexes. Run your test now and finally restore it.