D
D
driverx182020-05-04 15:18:21
MySQL
driverx18, 2020-05-04 15:18:21

Will it be correct if the coordinates are the primary key?

I want to store locations in the database, I came to the decision that it would be most normal to store longitude, latitude to identify a specific location (decimal field types). Is it normal if these two fields are a composite primary key (according to the performance in the sample on large volumes), or is it pointless, and should we go somehow differently?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
Dr. Bacon, 2020-05-04
@bacon

If in doubt, make a surrogate key. Another question to check, will the location longitude, latitude always be constant or is it likely that they will need to be edited a bit?

I
Igor, 2020-05-04
@IgorPI

I don't see much point.
Since, in most cases, it is not necessary to index longitude, latitude
. For example, there is a product, the product has a location.
How do you bind?
Two fields longitude, latitude?
Create a foreign key and don't fool yourself.
By the way, let me give you an example.
5eb0161c4b4bd030946462.png

D
Dmitry Entelis, 2020-05-04
@DmitriyEntelis

Offhand, this immediately subscribes you to some additional hemorrhoids in the code without any significant gain.
Imho it is correct to do the usual auto-increment + if your business logic requires it, hang up a composite unique key for latitude-longitude.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question