Inserting record with Microsoft Access

Frank Millman frank at chagford.com
Sat Feb 11 06:52:21 EST 2006


Steve Holden wrote:
> Albert Leibbrandt wrote:
> >
> > jeffhg582003 wrote:
> >
> >
> >>Hi,
> >>
> >>I am developing a python script which add records to
> >>a microsoft access tables. All my tables have autogenerated number
> >>fields. I am trying to capture the number generated from the insert but
> >>I am not exactly sure how to do that after an insert.
> >>
> > I had to do something similiar in sql server and the experts back then
> > told me that the only way is to write a stored procedure. aparently sql
> > server does not have sequences and I am guessing that access is the same.
> >
> Well the experts were wrong, I suspect. Try
>
>    SELECT @@IDENTITY
>
> to return the autonumber key created by the most recent INSERT.
>
> I believe this works for both SQL Server and Access (doesn't anyone use
> Google any more?).
>
> regards
>   Steve
>

I use SELECT IDENT_CURRENT('tablename').

SELECT @@IDENTITY returns the most recent of all inserts. If you have a
complex transaction which triggers inserts into other tables, it may
not return the one you want.

This one allows you to specify the tablename, and it will return the
most recent key inserted into that table.

I got this from the built-in help for SQLServer. I cannot say whether
it works for Access as well.

Frank




More information about the Python-list mailing list