Obtain the id to be inserted next to the auto-increment column.

Source: Internet
Author: User
How to obtain the id to be inserted next to the auto-increment Column

How to obtain the id to be inserted next to the auto-increment Column

The Code is as follows:
Declare @ Table_name varchar (60)
Set @ Table_name = 'pay _ inputpa ';
Select so. name Table_name, -- table name
SC. name Iden_Column_name, -- auto-increment field name
Ident_current (so. name) curr_value, -- current value of the auto-increment Field
Ident_incr (so. name) incr_value, -- auto-increment field Growth Value
Ident_seed (so. name) seed_value -- seed value of the auto-increment Field
From sysobjects so
Inner Join syscolumns SC
On so. id = SC. id
And columnproperty (SC. id, SC. name, 'isidentity ') = 1
Where upper (so. name) = upper (@ Table_name)
-- @ Table_name is the input parameter table name curr_value. This is the id to be inserted.

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.