db-derby-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hilz <hs...@hotmail.com>
Subject "generated by default" question
Date Mon, 29 May 2006 20:31:20 GMT
Hi all.
If i have a table A defined as follows:

create table A
(
ID     INTEGER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY,
NAME   VARCHAR(255)
);

then i do the following:

     insert into A (ID, NAME) values (1,'hello 1');

and then i do the following:

     insert into A (NAME) values ('hello 2');

I will get this error:

The statement was aborted because it would have caused a duplicate key 
value in a unique or primary key constraint or unique index identified 
by 'SQL060529010004440' defined on 'A'.

To avoid this, I will have to do :

     alter table....RESTART WITH....

Is there another way to make the autoincrement smart enough to know that 
the value already exists and just generate a new value for me?
I find it odd to have to set the "restart with" to skip the values that 
i set manually.

thanks for any help.




Mime
View raw message