MySQL id sequence

Posted by Michal Fronczyk on Stack Overflow See other posts from Stack Overflow or by Michal Fronczyk
Published on 2010-03-08T10:13:41Z Indexed on 2010/03/08 10:21 UTC
Read the original article Hit count: 486

Is this a correct way for id generation in MySQL ?

INSERT INTO Picture (PictureId,First_pick,Title,Description,File_Name,Is_Vertical)VALUES
((SELECT max(pictureid)+1 FROM Picture),0,?,?,?,?)

I mean if it is guaranted that PictureId will be unique when this query is run by many threads ?

I can't modify table structure. Should I use any specific locks, index or transaction isolation level ?

Regards, Michal

© Stack Overflow or respective owner

Related posts about mysql

Related posts about sequence