Posted By

gtalmes on 03/08/08


Tagged

key id primary


Versions (?)

Get Primary Key ID after an INSERT


 / Published in: SQL
 

  1. INSERT INTO users (firstName, lastName, email )
  2. VALUES ( '#FORM.LastName#', '#FORM.LastName#', '#FORM.email#' );
  3.  
  4. SELECT thisID = @@identity
  5.  
  6. ----------------------------------------------------------------------
  7.  
  8. The PRIMARY KEY IS then referenced AS Q_QueryName.thisID
  9.  
  10. "thisID" can be renamed TO whatever you LIKE
  11.  
  12. I USE this code IN ColdFusion, I assume it works IN any LANGUAGE that supports SQL querying.

Report this snippet  

You need to login to post a comment.