Get Primary Key ID after an INSERT


/ Published in: SQL
Save to your folder(s)



Copy this code and paste it in your HTML
  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


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.