更新表中所有行的有效方法 [英] Efficient way to update all rows in a table

查看:81
本文介绍了更新表中所有行的有效方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的桌子上有很多记录(可能超过500 000或1 000 000).我在此表中添加了新列,我需要使用此表中另一列的相应行值为该列中的每一行填充一个值.

I have a table with a lot of records (could be more than 500 000 or 1 000 000). I added a new column in this table and I need to fill a value for every row in the column, using the corresponding row value of another column in this table.

我试图使用单独的事务来选择每100条记录的下一个大块并更新它们的值,但是例如,要花费数小时来更新Oracle10中的所有记录.

I tried to use separate transactions for selecting every next chunk of 100 records and update the value for them, but still this takes hours to update all records in Oracle10 for example.

在SQL中最有效的方法是什么,而又不使用某些特定于方言的功能,那么它可以在任何地方(Oracle,MSSQL,MySQL,PostGre等)使用?

What is the most efficient way to do this in SQL, without using some dialect-specific features, so it works everywhere (Oracle, MSSQL, MySQL, PostGre etc.)?

附加信息:没有计算字段.有索引.使用生成的SQL语句逐行更新表.

ADDITIONAL INFO: There are no calculated fields. There are indexes. Used generated SQL statements which update the table row by row.

推荐答案

通常的方法是使用UPDATE:

The usual way is to use UPDATE:

UPDATE mytable
   SET new_column = <expr containing old_column>

您应该能够完成一次交易.

You should be able to do this is a single transaction.

这篇关于更新表中所有行的有效方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆