You are viewing a plain text version of this content. The canonical link for it is here.
Posted to derby-user@db.apache.org by "Jean T. Anderson" <jt...@bristowhill.com> on 2006/04/12 05:21:24 UTC

Is there a way to create auto increment columns?

Since others on derby-user might have the same question....

Question on #derby IRC:

derby newbie here...  Does anyone know if there is a way to create auto
increment columns in derby like mysql?

Answer given:

derby supports identity columns : see
http://db.apache.org/derby/docs/10.1/ref/rrefsqlj24513.html
and the full info for generated ... as identity is at
http://db.apache.org/derby/docs/10.1/ref/rrefsqlj37836.html

Re: Is there a way to create auto increment columns?

Posted by Yan Ma <po...@yahoo.com.cn>.
Two kinds of identity column:
GENERATED ALWAYS AS IDENTITY
example:
create table greatings (i int generated always as
identity);

GENERATED BY DEFAULT AS IDENITY.
example:
create table greatings (i int generated by default as
identity);

The difference is you cannot specify particular value
for the GENERATE ALWAY, but you can do so for the
later.
What's more, GENERATE BY DEFAULT doesn't guarantee
uniqueness. You can use a primary key or unique
constraint on the GENERATE BY DEFAULT identity column.

--- "Jean T. Anderson" <jt...@bristowhill.com> Wrote:

> Since others on derby-user might have the same
> question....
> 
> Question on #derby IRC:
> 
> derby newbie here...  Does anyone know if there is a
> way to create auto
> increment columns in derby like mysql?
> 
> Answer given:
> 
> derby supports identity columns : see
>
http://db.apache.org/derby/docs/10.1/ref/rrefsqlj24513.html
> and the full info for generated ... as identity is
> at
>
http://db.apache.org/derby/docs/10.1/ref/rrefsqlj37836.html
> 



	

	
		
___________________________________________________________ 
雅虎1G免费邮箱百分百防垃圾信 
http://cn.mail.yahoo.com/