Get ALL information about spatial index using SQL, including CELLS_PER_OBJECT and USING GEOGRAPHY_AUTO_GRID

All we need is an easy explanation of the problem, so here it is.

When I create a spatial index I can specify some extra parameters, e.g.

CREATE TABLE dbo.Test(
    Id bigint not null,
    Polygon geography not null
)
GO


CREATE SPATIAL INDEX IX_Test_Polygon ON dbo.Test
(
    Polygon
)
USING GEOGRAPHY_AUTO_GRID 
WITH (CELLS_PER_OBJECT = 12)
GO

If I then go to SSMS and script this index, then the script will contain these USING GEOGRAPHY_AUTO_GRID and WITH (CELLS_PER_OBJECT = 12). However, the view sys.indexes does not contain this information.

How can I get this information using SQL, not SSMS.

How to solve :

I know you bored from this bug, So we are here to help you! Take a deep breath and look at the explanation of your problem. We have many solutions to this problem, But we recommend you to use the first method because it is tested & true method that will 100% work for you.

Method 1

This information can be found in the system tables, sys.spatial_indexes and sys.spatial_index_tessellations. More info for these system tables at https://docs.microsoft.com/en-us/sql/relational-databases/system-catalog-views/spatial-data-catalog-views?view=sql-server-ver15.

Note: Use and implement method 1 because this method fully tested our system.
Thank you 🙂

All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

Leave a Reply