none
Current Identity Value of a Primary Key

    Question

  • Hello,

    I am trying to find out a solution to get the current identity value of a table.
    I need it for testing and I need NOT to change that value.

    On the "normal" SQL Server it works fine with:

    DBCC CHECKIDENT ('Tablename')

    But on CE it works not.

    When I try to ask google to find a solution for CHECKIDENT in SQL CE, I only get topics
    which describe how to reseed the identity, like e.g. with:
    ALTER TABLE TableName
     ALTER COLUMN ColumnName
     IDENTITY(1
    ,1
    )
    But as I said... I do not want to reseed, I only want to retrieve the current Identity of a Table (NOT the current max-value of my primary key column!).


    How can I do that?


    Regards,

    Martin
    Wednesday, January 06, 2010 2:58 PM

Answers

  • Try:

    SELECT AUTOINC_NEXT FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = N'Categories' AND COLUMN_NAME = N'Category ID'
    



    http://erikej.blogspot.com Erik Ejlskov Jensen - Please mark as answer, if this was it.
    • Marked as answer by macap Thursday, January 07, 2010 9:42 AM
    Wednesday, January 06, 2010 5:59 PM
    Moderator