What is Spatial Index in SQL Server


Spatial Index can only be created on Spatial columns. That is, the type of column must be geometry or geography. Let’s create a table with a column of geography type with the help of the following script and insert several sample records into it.

As can be seen from the above script, we will store the information of which company will be in which coordinate in this example table.

With the help of the following script, we can create spatial index on the column of geography type.

If you want to create a normal index on spatial columns, you will receive an error as follows.

Msg 1978, Level 16, State 1, Line 2

Column ‘Coordinate’ in table ‘dbo.SpatialIndexExampleTable’ is of a type that is invalid for use as a key column in an index or statistics.

Author: dbtut

We are a team with over 10 years of database management and BI experience. Our Expertises: Oracle, SQL Server, PostgreSQL, MySQL, MongoDB, Elasticsearch, Kibana, Grafana.

Leave a Reply

Your email address will not be published. Required fields are marked *