• Post Reply Bookmark Topic Watch Topic
  • New Topic

sql auto increment question

 
Aris Doxakis
Ranch Hand
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 809
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't need to insert id, insert rest of the details.
 
Paul Clapham
Sheriff
Posts: 21975
36
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 136
Android Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 36031
432
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Aris,
Yes, that is correct. The database takes care of the one field you left out.
 
my overalls have superpowers - they repel people who think fashion is important. Tiny ad:
the new thread boost feature brings a LOT of attention to your favorite threads
https://coderanch.com/t/674455/Thread-Boost-feature
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!