Data inserted by SQL server in asp.net is taken from the growth column

Source: Internet
Author: User

In recent database programming, you need to retrieve the value of the auto-increment column after executing SQL insert. It is easy to get this value in the database: return the last inserted record

You can use SELECT IDENT_CURRENT ('tablename') for automatic numbering.

You can also use the following code:

The code is as follows: Copy code

Select @ identity

Execute this statement after insert. On the internet, someone added a sentence before insert:

The code is as follows: Copy code

Set nocount on;

This statement does not return the queried row count.

So:

 

The code is as follows: Copy code
Set nocount on;
Insert into tbUser (a, B) values ("a", "B ");
Select @ identity;

Of course, you can add a trigger.

The code is as follows: Copy code


Create trigger trUser_insert on tbUser for insert

Select @ identity

Go


Return the next automatic number:

SELECT IDENT_CURRENT ('tablename') + (SELECT IDENT_INCR ('tablename '))
SELECT @ IDENTITY -- returns the last tag value generated in all tables of the current session.

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.