Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

is it good to increment a value automatically

Status
Not open for further replies.

Jefhandle

Technical User
Mar 9, 2005
69
DE
Hello,
Some people say to define a value (colume) as auto increment to increase the value in database is not good
because the database should operate it f.i increase the value userID in the bad way,where database do it automatically:
insert(x,y,z,.......)

They recommand to increase it by yourself
f.i. :
uID=getLastUserId()+1;
insert (uID,x,y,z,...)
what is better??
thanks
 
let the database do it

if you do this yourself --

uID=getLastUserId()+1;

then you also need to lock the table before doing this (and don't release the lock until after the INSERT)

locks are a performance killer

r937.com | rudy.ca
 
I completely agree with r937. Unless you are very careful, you will have issues with concurrent users trying to perform the increment at the same time.

Let the database engine do it. It's already multiuser safe.



Want the best answers? Ask the best questions! TANSTAAFL!
 
let say, I have a web site, which is visited at the same time by 1000 people, what is in this case? Is it too much or
still for the database engine a penny!!?
 
I doubt it's a ha'penny or a decipenny or a centipenny [and if those aren't words, they should be].

Especially compared to the performance hit you're going to take in the locking and unlocking of data by an extra-database-server entity (your code) to enforce multi-user safeness.

Use auto_increment. As Martha Stewart would say, "It's a good thing."



Want the best answers? Ask the best questions! TANSTAAFL!
 
are you talking about mysql only or generall? because i'm using MS Sql with the MS Server. Althougth the main features should be the same.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top