We Recommend

SQL Cookbook SQL Cookbook
Written in O'Reilly's popular Problem/Solution/Discussion style, the SQL Cookbook is sure to please. Anthony's credo is: "When it comes down to it, we all go to work, we all have bills to pay, and we all want to go home at a reasonable time and enjoy what's still available of our days." The SQL Cookbook moves quickly from problem to solution, saving you time each step of the way.


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.