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

后端 未结 4 1289
野性不改
野性不改 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:56

    In SQL Server, the IDENTITY property can be assigned to tinyint, smallint, int, bigint, decimal(p, 0), or numeric(p, 0) columns. Therefore the SCOPE_IDENTITY function has to return a data type that can encompass all of the above.

    As previous answers have said, just cast it to int on the server before returning it, then ADO.NET will detect its type as you expect.

提交回复
热议问题