returning an inserted SQL record

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Re: returning an inserted SQL record

    Found my answer...

    Select max(column) as ID
    from table
    JoeyTMann Guest

  2. Similar Questions and Discussions

    1. Inserting a timestamp when record is inserted
      Hi, how would I have a form insert a timestamp when the form was submitted for update into a table. I know there is a timestamp column type but I...
    2. ID of last record inserted
      Is it possible, with a MS Access database, to pull the ID of a record just inserted? I have found various threads and tutorials on various sites...
    3. Accepted way to grab the ID of a record you have just inserted?
      I have a page that inserts a new record into a DB. Upon doing so, I want to refresh the page and return the data that was just entered (including...
    4. Identity from inserted record
      I'm inserting a record into a SQL Server database. Once the record has been added, I need the Identity value that SQL Server created. Normally, the...
    5. mySQL / Last inserted record ID
      Hi, I'm using mySQL and wanted to get the ID of the record that I have just inserted in to the table (sentmessages). There is a function in mySQL...
  3. #2

    Default Re: returning an inserted SQL record

    You need to be real careful with this method, especially if you have a busy
    site, as you may "grab" the wrong ID if another user happens to perform an
    insert at the same time. One way that you can manage this is by using
    CFTRANSACTION to include the insert and select within the same transaction.

    Phil

    paross1 Guest

  4. #3

    Default Re: returning an inserted SQL record

    Actually, here's the right way to do it in SQL Server without requiring another
    database read and the possibility of another user slipping in and giving you
    the wrong ID. This is the official way of doing it. It took me years to find
    this, but it works every time: <CFQUERY NAME='LastValue' etc.> SET Nocount
    ON; INSERT INTO MyTable (blahblah) VALUES(blahblah); SELECT
    @@IDENTITY AS LastID; SET Nocount OFF; </CFQUERY> <!--Identity:
    #LastValue.LastID#--> Dave Morris

    BigDMorris Guest

Posting Permissions

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

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139