在SQL数据库中存储纬度和经度数据时要使用的数据类型是什么? [重复]

本文探讨了在标准SQL数据库中存储纬度和经度数据的最佳数据类型选择。讨论了float、decimal等类型,并考虑了特定操作的需求。推荐使用Decimal(9,6),适合大多数地理数据应用。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

本文翻译自:What datatype to use when storing latitude and longitude data in SQL databases? [duplicate]

When storing latitude or longitude data in an ANSI SQL compliant database, what datatype would be most appropriate? 在ANSI SQL兼容数据库中存储纬度或经度数据时,哪种数据类型最合适? Should float be used, or decimal , or ...? 应该使用float ,还是decimal ,还是......?

I'm aware that Oracle, MySql, and SQL Server have added some special datatypes specifically for handling geo data, but I'm interested in how you would store the information in a "plain vanilla" SQL database. 我知道Oracle,MySql和SQL Server已经添加了一些专门用于处理地理数据的特殊数据类型,但我对如何将信息存储在“普通的”SQL数据库中感兴趣。


#1楼

参考:https://stackoom.com/question/51f1/在SQL数据库中存储纬度和经度数据时要使用的数据类型是什么-重复


#2楼

Decimal(9,6)

如果你不习惯精度和比例参数,这里有一个格式字符串visual:

###.######


#3楼

我们使用float,但任何带有6位小数的数字风格也应该有效。


#4楼

我会使用具有适当精度的十进制数据。


#5楼

I think it depends on the operations you'll be needing to do most frequently. 我认为这取决于您最需要做的操作。

If you need the full value as a decimal number, then use decimal with appropriate precision and scale. 如果您需要十进制数的完整值,则使用具有适当精度和比例的十进制。 Float is way beyond your needs, I believe. 我相信Float超出了你的需求。

If you'll be converting to/from degºmin'sec"fraction notation often, I'd consider storing each value as an integer type (smallint, tinyint, tinyint, smallint?). 如果你经常转换为/来自degºmin'sec“分数表示法,我会考虑将每个值存储为整数类型(smallint,tinyint,tinyint,smallint?)。


#6楼

Well, you asked how to store Latitude/Longitude and my answer is: Don't, you might consider using the WGS 84 ( in Europe ETRS 89 ) as it is the standard for Geo references. 好吧,你问过如何存储纬度/经度,我的答案是:不要,你可以考虑使用WGS 84 (欧洲ETRS 89 ),因为它是地理参考的标准。

But that detail aside I used a User Defined Type in the days before SQL 2008 finally include geo support. 但除了那个细节,我在SQL 2008之前的几天使用了用户定义类型,最后包括地理支持。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值