Results 1 to 3 of 3
  1. #1
    Join Date
    Jul 2002
    Posts
    2

    Question Unanswered: Oralce-style sequences in MySQL?

    I'm in the process of migrating or Web sites over to MySQL from Oracle. I've used sequences in Oracle to generate IDs and I know that you can have auto-incrementing ID fields in MySQL, but there are a number of situations where I need to know what the new ID number is before inserting any records because there are child records to be added that reference the parent ID. Is there a popular solution to this or do I need to find a work-around?

    Thanks for any advice!

  2. #2
    Join Date
    Apr 2002
    Location
    Toronto, Canada
    Posts
    20,002
    it's all in how you ask the question

    if you have to know beforehand, then you have no choice but to "roll your own" sequences with some kind of table that you can update (e.g. set mimicsequence = mimicsequence + 1), with all the attendant problems of multithreading that this implies...

    on the other hand, if all you want id to use the just-inserted key as a foreign key in child records, then that's easy -- almost every database has this requirement, and mysql is no exception

    see mysql_insert_id()

    rudy
    http://rudy.ca/

  3. #3
    Join Date
    Jul 2002
    Posts
    2
    I believe all the scenarios I have will be covered by mysql_insert_id. Thanks for that!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •