SQL SERVER->> identity-related functions

Source: Internet
Author: User

The identity function--can only be used in a SELECT INTO statement to simulate the role of the identity property when inserting data to generate self-growth values.

SELECT IDENTITY (int1,1 as id_num  to  newtable  from oldtable;  

IDENT_INCR function-Returns the auto-growth value of the table, for example, if we want to increase by 1 each time, the function returns 1.

 UseAdventureWorks2012; GO  SELECTTABLE_SCHEMA, TABLE_NAME,IDENT_INCR(Table_schema+ '.' +TABLE_NAME) as IDENT_INCR   frominformation_schema. TABLESWHERE IDENT_INCR(Table_schema+ '.' +TABLE_NAME) is  not NULL;

Ident_seed function--the initial seed value of the auto-grow column

 UseAdventureWorks2012; GO  SELECTTABLE_SCHEMA, TABLE_NAME,Ident_seed(Table_schema+ '.' +TABLE_NAME) as Ident_seed   frominformation_schema. TABLESWHERE Ident_seed(Table_schema+ '.' +TABLE_NAME) is  not NULL; GO  

Ident_current-current autogrow value for the identity column of the table

 UseAdventureWorks2012; GO  SELECTTABLE_SCHEMA, TABLE_NAME, ident_current (Table_schema+ '.' +TABLE_NAME) as Ident_seed   frominformation_schema. TABLESWHEREIdent_current (Table_schema+ '.' +TABLE_NAME) is  not NULL; GO  

Scope_identity ()--maximum autogrow value generated in the current module (stored procedure)

@ @IDENTITY-the maximum autogrow value generated in the current session

SQL SERVER->> identity-related functions

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.