Find all spatial data columns in Azure SQL database

Article for: SQL Server Oracle database MySQL MariaDB

Spatial in Azure SQL are columns with the following data types: geometry, geography

The query below lists all columns with spatial data types.

Query

select schema_name(t.schema_id) + '.' + t.name as [table],
       c.column_id,
       c.name as column_name,
       type_name(user_type_id) as data_type
from sys.columns c
join sys.tables t
     on t.object_id = c.object_id
where type_name(user_type_id) in ('geometry', 'geography')
order by [table],
         c.column_id;

Columns

  • table - name of the (schema and table
  • column_id - column position in table
  • column_name - name of the column
  • data_type - type of spatial data:
    • GEOMETRY
    • GEOGRAPHY

Rows

  • One row represents one column with a spatial data type
  • Scope of rows: all columns containing spatial data types in the database
  • Ordered by schema name, table name and column position in table

Sample results