www.webdeveloper.com
Results 1 to 3 of 3

Thread: Any way to get auto_increment number immediately after creating a row?

  1. #1
    Join Date
    Jun 2006
    Location
    Under your bed
    Posts
    357

    Any way to get auto_increment number immediately after creating a row?

    Edit: Nevermind. I figured this out.
    Last edited by evenstar7139; 01-28-2013 at 06:16 PM.
    The better I get at programming, the more I appreciate arrays. Handy dandy things they are.

  2. #2
    Join Date
    Jan 2008
    Location
    Florida
    Posts
    1,227
    How about sharing your solution for future searches?

    Here's a solution for SQL Server:

    sql = "insert into table(row) values(value) SELECT @@IDENTITY"
    Set rs = Conn.Execute(sql).NextRecordSet

    NewID = rs(0)

  3. #3
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,157
    MySQL has a last_insert_id function (for which PHP has a corresponding function, by the way).

    PostgreSQL (and perhaps other DBMS's?) has a RETURNING clause you can use with an insert:
    Code:
    INSERT . . . RETURNING table_key_field
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles