sql - apache derby: specifying an ID for a column "GENERATED BY DEFAULT AS IDENTITY" -
the following sql statements apache derby works fine:
connect 'jdbc:derby://uri'; create schema test02; set schema test02 ; create table t ( id int not null primary key generated default identity (start 1, increment 1), name varchar(50) not null unique ); insert t(name) values ('name02'); insert t(name) values ('name03'); select * t; drop table t ; drop schema test02 restrict; disconnect;
output:
ij> insert t(name) values ('name02'); 1 row inserted/updated/deleted ij> insert t(name) values ('name03'); 1 row inserted/updated/deleted ij> select * t; id |name -------------------------------------------------------------- 1 |name02 2 |name03
but when 'know' id of records, , set id in insert statement:
## here set id column ij> insert t(id,name) values (1,'name01'); 1 row inserted/updated/deleted ij> insert t(name) values ('name02'); error 23505: statement aborted because have caused duplicate key value in unique or primary key constraint or unique index identified 'sql130515100041380' defined on 't'. ij> insert t(name) values ('name03'); 1 row inserted/updated/deleted ij> select * t; id |name -------------------------------------------------------------- 1 |name01 2 |name03 2 rows selected
how can fix this, how can have auto_increment column can, sometimes, set primary key ?
you're looking alter table ... restart with. here's docs:
http://db.apache.org/derby/docs/10.9/ref/rrefsqlj81859.html#rrefsqlj81859__rrefsqlj37860
Comments
Post a Comment