开发者

SQL table function or means to tell if identity column has been used?

I was curious if there is a way to tell if an IDENTITY column has ever been incremented if there is no data within the table. (i.e. data item wa开发者_运维知识库s inserted, then deleted)


For SQL Server you can use this approach:

SELECT IDENT_SEED(TABLE_NAME) AS Seed,
    IDENT_INCR(TABLE_NAME) AS Increment,
    IDENT_CURRENT(TABLE_NAME) AS Current_Identity,
    TABLE_NAME
FROM INFORMATION_SCHEMA.TABLES
WHERE OBJECTPROPERTY(OBJECT_ID(TABLE_NAME), 'TableHasIdentity') = 1
    AND TABLE_TYPE = 'BASE TABLE'

Note that you can reset the seed value in SQL Server, so the above apporach only tells you the current state of the seed, not whether there was ever any data in the table or not.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜