Identity

/*
Getting the current value of identity column of a table.
*/
SELECT
IDENT_CURRENT(‘Invoice’)

/* OR */

DBCC CHECKIDENT (invoice,NORESEED)

/*
Getting the incremental values of identity column of all tables from one database.
*/
USE training2005
SELECT
TABLE_NAME,IDENT_INCR(TABLE_NAME)AS
IDENT_INCR FROM INFORMATION_SCHEMA.TABLES
WHERE IDENT_INCR(TABLE_NAME)IS NOT NULL

/*
Getting the incremental value of identity column of a tables.
*/
SELECT TABLE_NAME,IDENT_INCR(TABLE_NAME)
AS IDENT_INCRFROM INFORMATION_SCHEMA.TABLES
WHERE IDENT_INCR(TABLE_NAME)
IS NOT NULL ANDTABLE_NAME=‘Invoice’

/*
Getting the start values
of identity column of all tables from one database
*/
USE training2005
SELECT TABLE_NAME, IDENT_SEED(TABLE_NAME)
AS IDENT_SEED FROM INFORMATION_SCHEMA.TABLES
WHERE IDENT_SEED(TABLE_NAME)IS NOT NULL

/*
Getting the startvalue of identity column of a table.
*/

SELECT TABLE_NAME, IDENT_SEED(TABLE_NAME)AS IDENT_SEED
FROM INFORMATION_SCHEMA.TABLESWHERE IDENT_SEED(TABLE_NAME) IS NOT NULL AND
TABLE_NAME=‘Invoice’

Leave a Reply

Your email address will not be published. Required fields are marked *