Choosing the type of primary key numeric (18.0)

I have inherited a SQL Server database where many tables have a primary key of type numeric(18,0) .

What reasons (historical perhaps?) Could this data type choose for the primary key?

+6
source share
4 answers

I would suggest that the SQL Server database was originally developed before SQL Server 2000, and that was the only way to get an integer larger than the standard int. Since then it would be more appropriate bigint.

+6
source

There is no right or wrong type for the key. You must select attributes and types that accurately represent the business domain or match the input. If the data you are writing is of a numeric type, then why don't you save it as a numeric?

+1
source

Maximum precision for an integer is assumed. Of course, I always use this for primary keys that come from a database generator that generates 64-bit numbers.

I really don't use SQL-Server, but the integer in my database is a 32-bit number, not 64 bits. As suggested in another answer, it is likely that it started in a database where this restriction was in place.

0
source

If you allow Hibernate to generate your schema, it will convert the long data type to numeric (19.0) using jtds. Perhaps something like this happened in your case.

0
source

Source: https://habr.com/ru/post/889715/


All Articles