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

sequence creation

 
Sri In
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Can anybody please help me how to generate sequence in
my sql 5.1.
 
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
Does MySql support sequences? I thought it didn't. In which case you will need to create a table to hold the sequence value.
 
Vamsi Mohan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Please find the sequence syntax:

CREATE SEQUENCE <sequence name> START WITH <start no.> MAXVALUE <max no.> INCREMENT BY <value> CACHE value;

Please use triggers, while inserting the records in the database. So automatically trigger will be triggered before inserting the record in the table.
 
Jan Cumps
Bartender
Posts: 2608
14
C++ Linux Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vamsi Mohan.Technology wrote:Please find the sequence syntax:

CREATE SEQUENCE <sequence name> START WITH <start no.> MAXVALUE <max no.> INCREMENT BY <value> CACHE value;

Please use triggers, while inserting the records in the database. So automatically trigger will be triggered before inserting the record in the table.
Does MySql 5.1 support that? I could not find it in the reference.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Use the auto_increment feature in mysql. See the create table documentation - http://dev.mysql.com/doc/refman/5.1/en/create-table.html

create a real sequence as follows:
"""




now when you want to get the next number in the sequence do:
"""


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.
 
Vamsi Mohan
Ranch Hand
Posts: 80
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, Mysql supports sequences. Please use appropriate syntax for creating sequences.
 
Paul Sturrock
Bartender
Posts: 10336
Eclipse IDE Hibernate Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Does it? Is this new functionality? The documentation seems to suggest otherwise.
 
ujjwal soni
Ranch Hand
Posts: 403
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

Mysql does not have any specific keyword for sequences....
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic