Solved

ID of last row inserted

Posted on 2003-11-04
3
182 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 50 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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
PHP Web Development 6 63
Modify Filter to cause a field to be not Required 3 46
PHP Curl Problem 10 68
blocking the posted data from outside of my domains 8 46
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…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
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.

738 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