dcsimg
Results 1 to 2 of 2

Thread: About LAST_INSERT_ID()

  1. #1
    Join Date
    Mar 2009
    Posts
    2

    About LAST_INSERT_ID()

    The reference Manual says above function returns the first auto generated value for an auto incrementing column.

    I have a database with a few tables. Now, there is a table "TABLE 1", the PK of which i use as FK in other tables.

    Now, My worry is, How do i handle this situation?

    I tried using LAST_INSERT_ID() that also did not help(no table or DB lock used). The data got corrupted.

    Suppose the AI id for one req was 6. Before the application could make a call to get the ID, other request was executed and the AI id returned was not correct.

    Now, the only option left out is to lock the table or DB and do the processing and thts how I can proceed.

    Just wanted to know if there is som other way to do this.

    Also, what lock should i Use table lock or DB lock? and approx. how much of a performance hit would it be?

    Other points to remeber:
    There are possibilities of simultaneous hits.
    This app needs to sclable. At any given point of time, around 100 users would be online.

  2. #2
    Join Date
    Feb 2006
    Posts
    4
    do not use auto increment for PK. this way LAST_INSERT_ID() , table locking can be avoided.
    Generate the PK yourself. Use as Pk in TABLE_1, and as FK in TABLE_2.

Posting Permissions

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