Longitude / Latitude Storage Database in SQL Server: Decimal (2 ,?)

In the table definition, I saw:

Latitude -> varchar(50) Longitude -> nvarchar(50) 

Immediately, obviously, I asked what was behind it: - it is positive that these values ​​are actually numerical in nature. In short: I postulated that they will be numerical, decimal in fact, and we will reject the philosophy of β€œthinking in lines.”

Now, for the horns of my dilemma, I simply went ahead and typed:

 Latitude -> decimal(2, 4) 

But hold on a second, 4 is wrong, isn't it? Correctly. Therefore, I thought that before the threshold, before I realize (per second, perhaps add) that 6 or 8 , perhaps, will not reduce it either. So first, first ...

Do I really insist that we do this? And if so ...

What precision should be stored to ensure that we can store all the value that needs to be inserted? For example, is there any predefined specification?

I don't just want to use something like Latitude -> decimal(2, 16) just to make it as erroneous as decimal(2, 2) in principle. And a similar question arises specifically for Longitude, but I assume that the answer to one will be sufficient for the other, i.e. decimal(3, answer) .

We are using MSSQL Server 2005.

It seems I am educating myself with SQL Server from manual experience and therefore do not make parts of this question irrelevant: I can use decimal(x, max(x)) not decimal(x, y) anyway! Leave the question as is for input.

+6
types sql sql-server geocoding
source share
2 answers

Decimal (2, 4) means 2 full digits of precision and 4 after the decimal point. SQL Server will not allow you to do this, but I think it means that you can store values ​​from -0.0099 to 0.0099.

I would recommend decimal (9, 6). It will store accurate to about 1/6 inch at the equator. Using 9 or less, since precision requires 5 bytes of memory, using 10-19 requires 9 bytes.

+19
source share

The maximum decimal precision in the sql server is currently 38. The scale can be up to 38. With it, the max decimal number will take 17 bites, where, when varchar takes any length, plus 2. So, if you went with varchar (38 ), with max you occupy 40 bits of data. The flip side is that varchar is not as limited in size as decimal. So what you really need to do is figure out how many decimal points you are going to allow, and then figure out your data type for it.

Sourse of information

+1
source share

All Articles