Getting the next ID without inserting a row

前端 未结 5 841
臣服心动
臣服心动 2021-02-05 10:50

Is it possible in SQL (SQL Server) to retrieve the next ID (integer) from an identity column in a table before, and without actually, inserting a row? This is not necessarily th

5条回答
  •  庸人自扰
    2021-02-05 11:02

    try IDENT_CURRENT:

    Select IDENT_CURRENT('yourtablename')
    

    This works even if you haven't inserted any rows in the current session:

    Returns the last identity value generated for a specified table or view. The last identity value generated can be for any session and any scope.

提交回复
热议问题