Re: Adding a serial column to a table.
Posted in 1996
Spetc@aol.com wrote:
: I'd like to add a serial column to a large (10 million rows) table and I want
: the numbering to be as if it was always there (1-10,000,000)
: I can figure out how to do it with load and unload, but this takes forever.
: Is there a faster method using SQL / 4GL?
Hi,
you can follow this scenario:
CREATE TABLE new_table
(serial_col SERIAL,
other_cols...
);
BEGIN WORK;
LOCK TABLE new_table IN EXCLUSIVE MODE;
INSERT INTO new_table (serial_col, other_cols...)
SELECT 0, other_cols...
FROM old_table;
COMMIT WORK;
DROP TABLE old_table;
RENAME TABLE new_table TO new_table;
If you don't have enough log space, you can insert smaller
parts of old_table to new_table, or turn off logging.
Good luck,
--
Zdeno Miklas SOFTEC spol. s r. o.
e-mail: ash@softec.sk Kutuzovova 23
phone : 42-7-273805 ext.128 831 03 Bratislava
fax : 42-7-272537 SLOVAKIA