Mysql, access, and mssql server

Source: Internet
Author: User
Tags mssql server

When you operate access and MSSQL, You need to execute a SELECT query to obtain the new insert Record ID. in MySQL, use $ newid = mysql_insert_id (); you can easily obtain the ID of the newly inserted record. The methods for getting new insert records for access, MSSQL, and MySQL databases are sorted out for reference.
1. PHP + MySQL, run the insert statement and then use

$ Newid = mysql_insert_id ();
New insert Record ID

2. ASP + access, use

Rs. Open SQL, Conn, 1, 3
Rs. addnew

After adding a record in this way, you can use

Newid = Rs. Fields ("ID ")
Obtain the ID of the newly inserted record.

3. ASP + MSSQL, use the conn.exe cute ("insert into...") statement to insert a new record, use

Newid = conn. Execute ("select scope_identity () from table") (0)
Obtain the latest record ID
In addition, you can use select ident_current (ID) in SQL2000 to [query the ID generated by the last insert operation], select @ identity [the auto-increment ID obtained after a series of updates].

In SQL, I will add that using scope_identity is more accurate.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.