Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Getting unique ID for INSERT

 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have a small problem I have come accross, which I can't see an obious way round.

I have a RegistrationServlet (for creating a new user) which inserts the details of the new user into two seperate tables in a MS SQL database.

The first insert puts the users personal data into a table called tblUsers (name, dob, tel no, address, etc). The second insert puts the users security details into a table called tblUserSecurity (username, password, etc).

The problem I have is, the only way to uniquely identify the user is from the ID column (from tblUsers) which is set as the primary key and automatically created for each record added, I need to somehow take this value for the new user and insert it into the tblSecurity table along with the username, password etc as a way of linking the user to their security details.

Any help would be greatly appreciated.

Cheers
 
praveen kanakarajan
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
im not a great expert.i think u can get the value of last identity by using the query
select @@identity
will return the latest identity value.Just try this im not sure.but hope will help you
 
Kevin P Smith
Ranch Hand
Posts: 362
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Cheers for that, but I have found a way to get the last record eneterd (I think), but tanks anyway. Always nice to have a plan 'B'.
 
Horatio Westock
Ranch Hand
Posts: 221
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may have solved this differently, but if I understand you problem, you could use something along the lines of:



Hope this helps (someone!)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic