File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JDBC and Relational Databases and the fly likes sql auto increment question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Databases » JDBC and Relational Databases
Bookmark "sql auto increment question" Watch "sql auto increment question" New topic

sql auto increment question

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136


im using sql 4.0 and i have created a table that has a field book_id which is a primary key and,integer with auto increment.How can i insert a new book?tried but still cant figure how to make auto increment work.

thnx in advance!!
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809
You don't need to insert id, insert rest of the details.

Asking Smart Questions FAQ - How To Put Your Code In Code Tags
Paul Clapham

Joined: Oct 14, 2005
Posts: 19973

It would be easier to advise if we knew what you had already tried. But the general idea is to leave the book-id column out of your INSERT statement and let the database generate the key value.
Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

so for me to understand a simple example:

insert into books(every field exept book_id) values(every value exept book_id)

is this right??
thnx alot!!
Jeanne Boyarsky
author & internet detective

Joined: May 26, 2003
Posts: 33124

Yes, that is correct. The database takes care of the one field you left out.

[OCA 8 book] [Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Other Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, TOGAF part 1 and part 2
I agree. Here's the link:
subject: sql auto increment question
It's not a secret anymore!