It depends on the db vendor and the primary key type (if it's anything other than an int it is a little more tricky). In SQL Server you can use the @@Identity immediately after the insert. It will return the last primary key (as long is it is an identity) which was inserted. There are some things to be careful of when using @@Identity, but it is fairly straightforward. Check Books Online for more detail.
In Access, AFAIK there is not an equivalent operator. What I usually do is select max(pk_id) from table where data = 'whatever I just inserted' That approach obviously has some pitfalls as well, but in practice it works pretty well. In Oracle, most likely you'd be using sequences, and can get the value out of the sequence before the insert. But in that case you probably wouldn't be asking the question ;) </rob> -----Original Message----- From: Kris Pilles [mailto:[EMAIL PROTECTED]] Sent: Tuesday, May 21, 2002 9:06 AM To: CF-Talk Subject: Query help How can Insert a record into a table (that I know how to do) but after the insert, I want to be able to know what the primary key for the record I just inserted... ______________________________________________________________________ Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Archives: http://www.mail-archive.com/[email protected]/ Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

