sql - Adding new columns to a column database having billions of rows -


I want to add a new column to the table, which already contains billions of rows, new columns are obtained from the current column .

For example,

  new_col1 = old_col1 + old_col2 new_col2 = old_col1 / old_col2  

I try to do this in the following way I am doing -

Add a new column

  Add an optional table table_name (column_1 column-definition, column_2 column-definition, ... column_en Column_definition)  

Read the rows one by one from the table and fill out the price for the new column.

There is no primary key in the database, so I can not specify a personal line to read the rows one by one, I have to select one which will give a huge result ( Consider billions of records).

Is there a better way to do this?

Different DBMS has different SQL bids, it is useful to specify how you Are using

You can use it in SQL Server, but whenever you select the data, the result is calculated, you can mark it as current, but make changes It may take some time but you can not do that if you are going to remove old columns.

Optionally allows a new column to be created and then update it in batches

UPDATE TOP (1000) table_name SET new_col1 = old_col1 + col_col2 WHERE new_col1 IS The tap is

Again the query is for SQL Server, but your DBMS will have options.

In addition, Mr. Hoppers comments about adding an index to the new column to ensure that the performance of UPDATE does not get worse as the more data is added . This update is a reading and writing process, the index will accelerate learning and delay writing will delay (maintain the index), but it should be meaningful.


Comments