Why does select SCOPE_IDENTITY() return a decimal instead of an integer?

后端 未结 4 1274
野性不改
野性不改 2020-11-27 05:10

So I have a table with an identity column as the primary key, so it is an integer. So, why does SCOPE_IDENTITY() always return a decimal value instead of an int

4条回答
  •  粉色の甜心
    2020-11-27 05:58

    Can't you just cast it before returning it from your query or stored proc (SPs alway return int anyway, but maybe you are using an output parameter)?

    Like SELECT CAST(SCOPE_IDENTITY() AS INT) AS LAST_IDENTITY

    And why it does this? Probably to be more flexible and handle larger numbers.

提交回复
热议问题