Adding serial key
Posted in 1996
Y'all
Jonathan properly chided me for not considering that adding a new column to
a table will result in it having null values - hence when you add an
integer and then convert it to serial you'll get a non-unique value error.
I no longer have the original message and can't remember whether the poor
soul I misdirected wanted to add a new column or convert an existing one.
(I checked usenet - ain't there yet)
Try this in 4gl:
DEFINE ctr, junk INTEGER
ALTER TABLE foo ADD (ser_val INTEGER)
DECLARE u_curs CURSOR FOR
SELECT ser_val FROM foo FOR UPDATE OF ser_val
LET ctr = 0
FOREACH u_curs INTO junk
LET ctr = ctr + 1
UPDATE foo SET ser_val = ctr WHERE CURRENT OF u_curs
END FOREACH
ALTER TABLE foo MODIFY (ser_val SERIAL)
# Altering it to serial does not add an index.
CREATE UNIQUE INDEX ix1 ON foo(ser_val)
cheers
j.
_____________________________________________________________________________
Jack Parker - Hewlett Packard, DMD/IS Boise, Idaho, USA
jparker@hpbs3645.boi.hp.com
_____________________________________________________________________________
If anything can go wrong, fix it. To hell with Murphy.
_____________________________________________________________________________
Any opinions expressed herein are my own and not those of my employers.
_____________________________________________________________________________