Re: Serial Field (fwd)
Posted in 1994
From ihor.j.kinal:
* In article <33ii07$ej0@emory.mathcs.emory.edu>, kurt.vanwagoner@sltrib.com (Kurt Vanwagoner) writes:
* > Is there a way to reset a serial field to zero, without dropping the
* > table. Assuming there is no data in the table. I am using Informix
* > online 5 on a NCR unix box.
* >
*
* I've seen some suggestions to alter the field to integer. While that
* might work, if the table is REALLY large, it would take a LONG time
* [and the alter might fail, if you don't have the spare space].
*
* Much easier is to insert a value one less than the max value for a long,
* then add another record [or maybe two]. Informix will then roll the
* serial key around to zero. BUT, note that it WILL REASSIGN keys
* in sequence, so you might get duplicate keys [I think], if you
* have any old records.
*
* [Note, I haven't really tried it, but that's what I was taught in the
* Admin class a couple of years ago, so all disclaimers apply].
Every time I tried to insert MAX-1 into the serial field, then the next
insert is not 1 unless all values up to MAX-1 have been used. For example:
CREATE TABLE ser_table ( ser_fld SERIAL NOT NULL );
INSERT INTO ser_table VALUES ( 0 );
INSERT INTO ser_table VALUES ( 0 );
INSERT INTO ser_table VALUES ( 0 );
INSERT INTO ser_table VALUES ( 0 );
INSERT INTO ser_table VALUES ( MAX - 1 ); -- I think it's 2147483647
INSERT INTO ser_table VALUES ( 0 ); -- This has a value of 5
Robert Minter |Data Systems Support| \\\\\\_///
Programmer, Software Development | Orange, CA | ( _ _ )
internet: rob@dssmktg.com | Tel: 714.771.0454 | (| ^ |)
bangpath: uunet.uu.net!dssmktg!rob| Fax: 714.771.3028 | \\`-'/
#include <disclaimer.h> SURF'S UP \\_/