Retrieving the value of an identity field of a new record

Retrieving the value of an identity field of a new record

Post by Matthew Fiel » Wed, 03 Jun 1998 04:00:00



Hi all,

I have a problem that seems like there should be a simple solution to.
I have a table that's only unique key is an identity field.  I need to
know how to retrieve the value of this column for the record that has
just been inserted.  Keep in mind that many inserts must be occuring at
the same time and the SQL that does the insert needs the value of the
column in the record that it inserted and no other SQL that is currently
doing inserts can recieve that value.

I hope that I have been clear.

Thanks for any help
Matthew Field

 
 
 

Retrieving the value of an identity field of a new record

Post by Michael Weave » Wed, 03 Jun 1998 04:00:00


Matthew,


to the current session.

Michael Weaver (MCP SQL / NT)

 
 
 

Retrieving the value of an identity field of a new record

Post by Matthew Paulso » Wed, 03 Jun 1998 04:00:00


Hi.  Try:

---------------------------------
begin transaction

< do your insert here >


commit transaction
----------------------------------

That should allow you to get the last value you inserted before anybody else
gets a chance to insert another.

Be careful retriving the rows from the select querry when using dblib.  I've
found that while it does return the correct value, it does so a large number
of times -- once for every row in the table.  I've put an "sqlcanquery"
after retreiving the first row to get around the problem.  Anybody else have
that problem?


> Hi all,

> I have a problem that seems like there should be a simple solution to.
> I have a table that's only unique key is an identity field.  I need to
> know how to retrieve the value of this column for the record that has
> just been inserted.  Keep in mind that many inserts must be occuring at
> the same time and the SQL that does the insert needs the value of the
> column in the record that it inserted and no other SQL that is currently
> doing inserts can recieve that value.

> I hope that I have been clear.

> Thanks for any help
> Matthew Field


 
 
 

1. Retrieving identity field value when adding new record

I'm sure I'm missing something really obvious here, but how do I retrieve
the value of an itentity field when adding a new record.

When using AddNew, the identity field is not set until the Update occurs, by
which time I've lost the new record.

I used to use rst.LastModified with DAO.  Is there some equivalent in ADO,
or is there a way I could acheive this with subqueries?

Thanks

Ian

2. how to find the number of rows updated in a trigger

3. Retrieving Identity value after inserting a record

4. Paradox for Windows vs MS Word 6

5. Retrieving Identity Colum after Adding new Record

6. ANY ACCESS SECURITY E

7. Retrieving the value of an Identity field on insert

8. Powerbuilder?

9. Retrieve Identity value (select @@identity...)

10. Retrieving the Identity field after a record update

11. Retrieve value of autoincrement field with inserted record

12. Retrieving newest records when fields are duplicated (2 nd Posting )

13. Getting Identity field for new record.