[英]Update column for few million rows in one table
I need to update two columns from one table which conatins few million rows. 我需要从一张表中更新两列,这意味着几百万行。 What is the most efficient way for doing this?
最有效的方法是什么?
It will be something like this: 将会是这样的:
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD'),
column_two = to_date('11/11/11', 'RR/MM/DD');
or this: 或这个:
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD');
update my_table set column_two = to_date('11/11/11', 'RR/MM/DD');
Or there is a better way? 还是有更好的方法?
The most efficient way to update a table with million rows is not to perform update operation at all and rather create a new table with updated values. 更新具有百万行的表的最有效方法是根本不执行更新操作,而是创建具有更新值的新表。
- Create a new table with updated columns while creation.
创建时使用更新的列创建一个新表。
- Notice all the Synonyms, Grants, Constraints, Indexes.
注意所有的同义词,授权,约束,索引。
- Drop the old table.
放下旧桌子。
- Rename new table to old table.
将新表重命名为旧表。
- Recreated grants, synonyms, constraints, indexes.
重新创建的赠款,同义词,约束,索引。
If you don't want to create a new table, just break it up into chunks. 如果您不想创建一个新表,只需将其分解成几块即可。
update my_table set column_one = to_date('11/11/11', 'RR/MM/DD'),
column_two = to_date('11/11/11', 'RR/MM/DD')
where rownum < 1000
AND column_one <> to_date('11/11/11', 'RR/MM/DD')
AND column_two <> to_date('11/11/11', 'RR/MM/DD');
@Incognito's answer is probably more performant. @Incognito的答案可能更有效。 Try this way if you're meaning for 'efficient' was less time spent on writing code.
如果您要表示“高效”的意思是花费更少的时间来编写代码,请尝试这种方式。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.