MySQL Forums
Forum List  »  Docs

MySQL Tutorial: LAST_INSERT_ID()
Posted by: Michael Reeves
Date: September 14, 2004 07:43AM

Posted this yesterday to the newbie list but didn't get any response.
--------------------------------
I'm working my way through the MySQL Tutorial, and I'm having trouble with the Foreign Keys section. I'm using MySQL 4.1.4 gamma, and I'm wondering if this is a bug.

When I created the shirt table, using LAST_INSERT_ID() the owner field isn't incrementing correctly. I added an extra line for the first owner to see what was going on, but here's what I get:

id | style | color | owner
1 | polo | blue | 1
2 | dress | white | 1
3 | t-shirt | blue | 2
4 | polo | red | 3 * my inserted record
5 | dress | orange | 2
6 | polo | red | 5
7 | dress | blue | 6
8 | t-shirt | white | 7

Owner should be 1 or 2 for all of them according to the documentation.

----------------------------------
Having looked at it further, it's pretty obvious that LAST_INSERT_ID() is taking the last ID irrespective of which table it came from. Is this a documentation bug, or a product bug?

Options: ReplyQuote


Subject
Views
Written By
Posted
MySQL Tutorial: LAST_INSERT_ID()
65867
September 14, 2004 07:43AM
23699
October 18, 2004 08:50AM
17911
December 16, 2004 12:15AM
14224
March 08, 2007 10:14PM


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.