For each database engine we have different ways to retrieve the last inserted id, let’s say that we have the following table:

Product(productID, name, description)

And we have the following query:

<cfquery name=”test” datasource=”my_data”>

insert into Product (name, description) values (‘someProd’, ‘description O fThe Prod’)


now for each engine we can get the last ID in the following way:

MSSQL: <cfoutput>#test.IDENTITYCOL#</cfoutput>

Oracle: <cfoutput>#test.ROWID#</cfoutput>



MySQL: <cfoutput>#test.GENERATED_KEY#</cfoutput>

I guess that this is because each engine uses different methods and the internal database variables are different from engine to engine.

We can get more information on the ColdFusion web site here.