AUTO_INCREMENT assigns a value = (largest value in that column) + 1.
So insert your first row manually with the started value you want. Then let
mysql auto increment from there.
-Josh
-----Original Message-----
From: Skip Montanaro [mailto:skip@stripped]
Sent: Tuesday, February 29, 2000 7:06 PM
To: mysql@stripped
Subject: is there any way to AUTO_INCREMENT fields with non-zero
DEFAULTs?
I want to set a non-zero default for an unsigned integer field and also have
that field auto increment. Ideally, I'd like to use something like:
use test;
drop table if exists foo;
CREATE TABLE foo (
id int unsigned DEFAULT 2415919104 NOT NULL AUTO_INCREMENT,
UNIQUE id (id),
value varchar(10)
);
insert foo (value) values ("zero");
insert foo (value) values ("one");
select * from foo;
and have MySQL display:
id value
2415919104 zero
2415919105 one
Instead it displays:
id value
1 zero
2 one
I see in the docs where it says "AUTO_INCREMENT sequences begin with 1".
Shouldn't it therefore be an error or warning to use both DEFAULT and
AUTO_INCREMENT in the same column definition? Failing that, why does
AUTO_INCREMENT impose this seemingly arbitrary restriction on where it can
start counting from?
Is there some way I can get the behavior I want? Generally, what I want is
to be able to have the id column start at some non-zero value and get
incremented every time I insert a new row into the table without having to
query some values from the server or explicitly set that column, since I'll
be loading data in from CSV files and won't easily have the luxury of
computing column values.
Thanks,
Skip Montanaro | http://www.mojam.com/
skip@stripped | http://www.musi-cal.com/