Initial/reset serial value
Posted in 1999
Topics: General Discussion
Informix manuals state that "You can use the MODIFY clause to reset the next value of a serial column (Syntax Guide)" and "The default serial starting number is 1, but you can assign an initial value, n, when you create or alter the table (Reference Guide)" -- then fail to provide the syntax. Well, my Informix SQL syntax crystal ball just broke. What is the syntax for these operations? And exactly where in the documentation is this?
Red Valsen wrote:
>
> Informix manuals state that "You can use the MODIFY clause to reset the
> next value of a serial column (Syntax Guide)" and "The default serial
> starting number is 1, but you can assign an initial value, n, when you
> create or alter the table (Reference Guide)" -- then fail to provide the
> syntax.
It is there. If you look at the syntax of the SERIAL type declaration it
shows the desired initial SERIAL value in parenthesis following the type
specifier. In an ALTER you just modify the column to the same type but
append the initializer. Note that you can ONLY increase the initial value
above the largest current value in any row in the table EVER. So if the
highest valid serial value is 10001 and someone accidentally inserted or
updated a row with a serial value of 2000002 deleting or updating the
aberrant row and ALTERing the table to 10001 will be ineffectual. What
you have to do it cleanup then ALTER the value to the maximum value (2^31-1).
Then it will wrap to insert the lowest currently unused value. Once one
row has been inserted this way you can alter again to set it to say 10002 so
that old deleted values are not reused. Syntax examples below.
> Well, my Informix SQL syntax crystal ball just broke. What is the
> syntax for these operations? And exactly where in the documentation is
> this?
CREATE TABLE mine (
one SERIAL(12),
...
);
ALTER TABLE mine MODIFY one SERIAL(25);
Art S. Kagel