Php+mssql get last Insert ID value problem (online etc ~)
I remember MySQL has a mysql_insert_id () function to get the last inserted ID, such as $newid = mysql_insert_id (); What about the MSSQL database? Is there such a function? How do I output the last inserted ID?
------Solution--------------------
At least not found in the manual.
Query one time.
------Solution--------------------
Query under SELECT @ @IDENTITY
MSSQL has its own system variables.
------Solution--------------------
discuss
Query under SELECT @ @IDENTITY
MSSQL has its own system variables.
------Solution--------------------
discuss
No, do you have to write that? Is there any other way? I just looked for a bit, did not find such a function, the combination of mssql+php I am very uncomfortable, I am doing is a master-slave table structure of things, to insert data from the table need to store the main table ID, help to think of a way to achieve this problem.
------Solution--------------------
discuss
is not the difficult problem, if the primary key is the number of such, not the increment identifier, then how to deal with AH?
------Solution--------------------
SELECT @ @IDENTITY can be used as long as there is an insert
Didn't seem to have seen the upstairs problem.
Is it a problem when there is a lot of concurrency?
Write a stored procedure.
------Solution--------------------
In addition to stored procedures, the simplest and most straightforward approach is to construct a query that guarantees the uniqueness of the query criteria.
------Solution--------------------
Select once after inserting ... Find out the ID.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.