Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Auto increment fields , evil or good?

 
raminaa niilian
Ranch Hand
Posts: 551
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
Thank you for reading my post.
here is my question :
using auto increment fields are good or bad ?
what is best practice for them : When to use them , how to use them , when to avoide them?

consider the following condition :
I have one table which is related to another table in a one-to-one relation.
parent table primary key is auto increment (what should i use if auto increment is evil?)
now i insert a record into parent Table , i should include parent table Primary key into child table
to relate it with parent table.
after i insert parent record i should execute a select statement to find the inserted record Primary key and include it into child table record
My question is :
how i can avoide this select statement execution ?
what should i use instead of That auto increment field ?


Thank you so much.
[ November 22, 2005: Message edited by: Bear Bibeault ]
 
Jeanne Boyarsky
author & internet detective
Marshal
Posts: 35279
384
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Raminaa,
Auto increment fields aren't bad/evil if used appropriately. It sounds like your use is a good one.

Many database let you return the generated keys rather than doing a separate select. This was introduced with JDBC 3.0. See if your database supports it:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic