SQL Spatial Data Types

Introduction

Spatial data types in SQL allow you to store and manipulate geographic information. This topic provides an overview of spatial data types and their use in SQL Server.

Geography Data Types

The geography data type represents points, lines, and areas in two-dimensional space. It is based on the ellipsoidal model of the Earth.

Common geography data types include:

Geometry Data Types

The geometry data type represents points and areas in two-dimensional space. It is based on a planar model of the Earth, which is a simpler representation than the geography data type.

Common geometry data types include:

Spatial Functions

Spatial functions are built-in SQL functions that perform spatial operations, such as calculating distances, finding intersections, and determining containment.

Some example spatial functions include:

Example: Calculating Distance Between Two Points


SELECT ST_Distance(geography_point1, geography_point2) AS distance
FROM my_table;