jQuery in Action, 2nd edition*
The moose likes JDBC 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
Bookmark "sql auto increment question" Watch "sql auto increment question" New topic
Author

sql auto increment question

Aris Doxakis
Ranch Hand

Joined: Dec 05, 2004
Posts: 136

hello,

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
Bartender

Joined: Oct 14, 2005
Posts: 18541
    
    8

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
internet detective
Marshal

Joined: May 26, 2003
Posts: 30116
    
150

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


[Blog] [JavaRanch FAQ] [How To Ask Questions The Smart Way] [Book Promos]
Blogging on Certs: SCEA Part 1, Part 2 & 3, Core Spring 3, OCAJP, OCPJP beta, TOGAF part 1 and part 2
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: sql auto increment question
 
Similar Threads
autoincrement invoice
is it a must to have id for each mapping file ?
Pb with auto-increment field
Primary key generated as 5000000000006877 when generator class used is native
Java DB - Reset auto-increment primary key