Jul
6
2009
6
2009
Create AutoIncrement column/field in Apache Derby
While creating a table a particular column / field can be made autoincrement as :
CREATE TABLE students ( id INTEGER NOT NULL GENERATED ALWAYS AS IDENTITY (START WITH 1, INCREMENT BY 1), name VARCHAR(24) NOT NULL, address VARCHAR(1024), CONSTRAINT primary_key PRIMARY KEY (id) ) ;
The value of an autoincrement column increments automatically with every insert and doesnt need to be specified in the insert command. It is 1 + the value of the same field in the previous row.
Now data can be inserted as :
insert into students(name , address) values('Sanjay' , 'New Delhi');
Note that the value for the id field (which is an autoincrement field) is not specified. It fills automatically by taking the value of the previous row and adding 1 to it.
Popularity: 40% [?]
Subscribe
Recent Posts
- Compile wxwebconnect on Ubuntu 11.04 64 bit
- Disqus Comments Importer Script in PHP
- Beginners’ guide to socket programming with winsock
- Handle multiple socket connections with fd_set and select on Linux
- Beginners guide to socket programming in C on Linux
- Gui whois client in python with wxpython
- Whois client code in C with Linux sockets
- str_replace for C
- Easy to use C/C++ IDE for Ubuntu Linux
- Get local ip in C on linux
Binarytides
Tags
apache
applications
box2d
bsnl
c
chrome
cron
css
database
dns
firefox
flash
freelance
game programming
gd
graphs
hacking
htaccess
html
html5
imagemagick
java
javascript
libpcap
linux
mod rewrite
moneybookers
mootools
mvc
mysql
networking
payment
paypal
php
phpmyadmin
python
ruby
security
Sockets
software
swing
ubuntu
winpcap
winsock
xdebug
An article by Binary Tides





I had a question.So how do you get that id that was generated???
Need to then add data to a table that uses that PK as a FK.
Thanks
[...] with Primary Key Column "GENERATED … AS IDENTITY" 2. Create AutoIncrement column/field in Apache Derby 3. Derby PK auto-increment woes This entry was posted in DB and tagged Derby. Bookmark [...]