Groups | Blog | Home
all groups > sql server (alternate) > september 2003 >

sql server (alternate) : Last insert id



Simon Hayes
9/12/2003 11:20:50 AM

[quoted text, click to view]

Assuming that you're using an IDENTITY column to generate the IDs, then the
scope_identity() function will give the last ID inserted. There are also
ident_current() and @@identity - see Books Online for an explanation - but
scope_identity() is probably the one you want.

Simon

George Hill
9/12/2003 12:01:17 PM
Hi

I am trying to import several master detail records from files to ms sql
server.
I have orders file and order_items file that has several rows for each
order.
If I insert programmatically these records how can find out which order ID
was the last inserted, so that I can attach the subsesquent row items to a
proper order.

I am quite new to ms sql server. I have used mysql a lot and there I could
use mysql_insert_id to find out the last autoincremented filed number.
I am looking for a similar method for ms sql server 2000.

TIA
George

AddThis Social Bookmark Button