faqts : Computers : Programming : Languages : PHP : Database Backed Sites : MSSQL

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

75 of 90 people (83%) answered Yes
Recently 6 of 10 people (60%) answered Yes

Entry

How do I know the last AUTOINCREMENT ID of a inserted record in a ODBC or MSSQL database? (equiv. MySQL_insertid)

Sep 23rd, 2000 19:45
Adrian Kubala, Fernando Moreira,


I don't know about ODBC, but MSSQL has a function, "@@IDENTITY" which
returns the last inserted ID. Use it like so:
$result = mssql_query("SELECT @@IDENTITY AS lastID");
$record = mssql_fetch_array($result);
$lastid = $record["lastID"];