Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

ID of last row inserted

Posted on 2003-11-04
3
Medium Priority
?
185 Views
Last Modified: 2009-12-16
How can I get the primary key of the row I just inserted? I am using the mssql_ functions, MS SQL Server

thanks,

Rich
0
Comment
Question by:RichardFox
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
3 Comments
 
LVL 33

Accepted Solution

by:
snoyes_jw earned 200 total points
ID: 9681960
Switch your application over to mySql and use mysql_insert_id().

Oh, you wanted a serious answer.  Try
$query = "SELECT @@IDENTITY";
0
 

Author Comment

by:RichardFox
ID: 9682212
Of course I would use MySQL given a choice!

Thanks jw

Rich
0
 

Expert Comment

by:oscarschulz
ID: 9695759
using @@identity may faile in different cases. I do it like that. I add a additional collum with default NULL to the table.   When inserting a new row i put a value in that column. Then I search for the row with that value and take the ID from that row. For preaparing the next insert you have to set  the value in the additional colllum to Null.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit (http://en.wikipedia.org/wiki/PHPUnit) and similar technologies have enjoyed wide adoption, making it possib…
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

722 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question