Sign in using Google or Yahoo! id.  

MySQL Sequence

 Comments Share:   Twitter   Reddit   HackerNews   Facebook 

From: http://forums.mysql.com/read.php?61,143867,194058#msg-194058

Create sequence table:

create table sequence ( 
  name varchar(64) primary key, 
  last_val int unsigned not null 
) engine=myisam; 

Update with value:

INSERT INTO sequence (name, last_val) VALUES ('seq', 0);

To get the new sequence number:

UPDATE sequence SET last_val=@val:=last_val+1
  WHERE name='seq';

Note: Uses myisam engine, so does not respect transactions.

Posted on July 16, 2010 08:27 AM by Subhash Chandran
db transaction mysql
blog comments powered by Disqus