can derby have a "sequence" column? : Apache
This is a discussion on can derby have a "sequence" column? within the Apache forums in Application Servers & Tools category; If I remember correctly, Oracle can define a column as being a "sequence", which is a garaunteed unique integer for each record. Can derby do this? A create table example would be nice. -- firstname lastname supermail99-97jfqw80gc6171pxa8y+qA @ public.gmane.org -- http://www.fastmail.fm - Send your email first class...
| Apache Apache discussions surrounding web server, tomcat, derby, jdo, excalibur, jackrabbit, logging, mina, mod-auth, mod-dav, mod-log, mod-proxy, openjpa, ode, uima and webservices |
![]() |
| | LinkBack | Thread Tools |
|
#1
| |||
| |||
| "sequence", which is a garaunteed unique integer for each record. Can derby do this? A create table example would be nice. -- firstname lastname supermail99-97jfqw80gc6171pxa8y+qA@public.gmane.org -- http://www.fastmail.fm - Send your email first class |
|
#2
| |||
| |||
| Yes. For example: CREATE TABLE GROUPS( ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (start with 0, increment by 1), NAME VARCHAR(25) NOT NULL, DESCRIPTION VARCHAR(255), PRIMARY KEY (ID) ) Regards, Suavi Demir At 06:52 PM 9/16/2005, you wrote: >If I remember correctly, Oracle can define a column as being a >"sequence", which is a garaunteed unique integer for each record. Can >derby do this? A create table example would be nice. >-- > firstname lastname > supermail99-97jfqw80gc6171pxa8y+qA@public.gmane.org |
|
#3
| |||
| |||
| firstname lastname wrote: > If I remember correctly, Oracle can define a column as being a > "sequence", which is a garaunteed unique integer for each record. Can > derby do this? A create table example would be nice. Derby supports generated "identity" columns; examples are here: http://db.apache.org/derby/docs/10.1...sqlj37836.html regards, -jean |
|
#4
| |||
| |||
| how do you get the last serial used in a table? On 9/16/05, Jean T. Anderson <jta-N3a1/uIFnjIFraO2wh7vUA@public.gmane.org> wrote: > > firstname lastname wrote: > > If I remember correctly, Oracle can define a column as being a > > "sequence", which is a garaunteed unique integer for each record. Can > > derby do this? A create table example would be nice. > > Derby supports generated "identity" columns; examples are here: > > http://db.apache.org/derby/docs/10.1...sqlj37836.html > > regards, > > -jean > |
|
#5
| |||
| |||
| Good example but, how do insert a row to this table from JDBC ? Using ij, it's just a matter of using the DEFAULT parameter, however, the JDBC preparedstatement class has no setDefault() method. On Fri, 16 Sep 2005 20:18:04 -0700, "Ali Demir" <demir4-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> said: > Yes. For example: > > CREATE TABLE GROUPS( > ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (start with 0, > increment by 1), > NAME VARCHAR(25) NOT NULL, > DESCRIPTION VARCHAR(255), > PRIMARY KEY (ID) > ) > > Regards, > Suavi Demir > > At 06:52 PM 9/16/2005, you wrote: > >If I remember correctly, Oracle can define a column as being a > >"sequence", which is a garaunteed unique integer for each record. Can > >derby do this? A create table example would be nice. > >-- > > firstname lastname > > supermail99-97jfqw80gc6171pxa8y+qA@public.gmane.org > > -- firstname lastname supermail99-97jfqw80gc6171pxa8y+qA@public.gmane.org -- http://www.fastmail.fm - Access your email from home and the web |
|
#6
| |||
| |||
| The IDENTITY_VAL_LOCAL function returns the most recently assigned number: http://db.apache.org/derby/docs/10.1...entityvallocal cheers, -jean Mag Gam wrote: > how do you get the last serial used in a table? > > > > On 9/16/05, *Jean T. Anderson* <jta-N3a1/uIFnjIFraO2wh7vUA@public.gmane.org > <mailto:jta-N3a1/uIFnjIFraO2wh7vUA@public.gmane.org>> wrote: > > firstname lastname wrote: > > If I remember correctly, Oracle can define a column as being a > > "sequence", which is a garaunteed unique integer for each record. Can > > derby do this? A create table example would be nice. > > Derby supports generated "identity" columns; examples are here: > > http://db.apache.org/derby/docs/10.1...sqlj37836.html > <http://db.apache.org/derby/docs/10.1/ref/rrefsqlj37836.html> > > regards, > > -jean > > |
|
#7
| |||
| |||
| firstname lastname wrote: > Good example but, how do insert a row to this table from JDBC ? Using > ij, it's > just a matter of using the DEFAULT parameter, however, the JDBC > preparedstatement > class has no setDefault() method. The DEFAULT keyword is part of SQL, not ij. These SQL statements should all work in JDBC as a PreparedStatement INSERT INTO GROUPS(ID, NAME, DESCRIPTION) VALUES (DEFAULT, ?, ?) INSERT INTO GROUPS(NAME, DESCRIPTION) VALUES (?, ?) INSERT INTO GROUPS VALUES (DEFAULT, ?, ?) Dan. > > On Fri, 16 Sep 2005 20:18:04 -0700, "Ali Demir" <demir4-/E1597aS9LQAvxtiuMwx3w@public.gmane.org> said: > >>Yes. For example: >> >>CREATE TABLE GROUPS( >> ID INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (start with 0, >>increment by 1), >> NAME VARCHAR(25) NOT NULL, >> DESCRIPTION VARCHAR(255), >> PRIMARY KEY (ID) >>) >> |

