Re: How to generate sequence in MySql
create a real sequence as follows:
"""
create table sequence (
name varchar(64) primary key,
last_val int unsigned not null
) engine=myisam;
INSERT INTO sequence (name, last_val) VALUES ('seq', 0);
"""
now when you want to get the next number in the sequence do:
"""
UPDATE sequence SET last_val=@val:=last_val+1 WHERE name='table_changes';
"""
the key here is that the sequence table is myisam, and so does not respect transactions. if you use a table that respects transactions, you will block when there are multiple transactions trying to get a sequence, whereas what you want is to just get a sequence.
Subject
Views
Written By
Posted
167397
March 13, 2007 08:05AM
73308
March 22, 2007 10:34PM
66836
March 26, 2007 08:49AM
53596
March 26, 2007 09:31PM
30757
April 04, 2007 03:00AM
24407
April 05, 2007 02:37AM
21440
November 10, 2008 06:40AM
26400
November 21, 2007 03:50AM
Re: How to generate sequence in MySql
30110
January 29, 2008 08:33PM
17588
February 06, 2008 12:16PM
18382
October 15, 2008 01:03PM
12292
November 05, 2008 09:50AM
14115
November 10, 2008 06:32AM
15545
December 14, 2008 07:08AM
18320
January 23, 2009 05:38PM
8559
March 16, 2009 09:00AM
10341
March 16, 2009 09:18AM
8480
March 16, 2009 09:51AM
9372
March 16, 2009 10:23AM
8305
April 12, 2009 07:58AM
9857
April 03, 2009 03:07PM
Sorry, you can't reply to this topic. It has been closed.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion
of Oracle or any other party.