SQL Flow Field Guide

geometry.STTouches

Catalog support for SQL Server 2022 (16.x) and 2025 (17.x)

spatial predicate STTouches

What changes

Input
one or two spatial instances
Output or change
bit
Return type
SQL Server return type: bit CLR return type: SqlBoolean

Syntax at a glance

.STTouches ( other_geometry )

Work example

Use geometry.STTouches to test whether two shapes meet at boundaries without interior overlap.

Check matching SRIDs and include a boundary-only case. Confirm both values use the same SRID before comparing or combining them.

Check your work The squares share an edge but no interior area, so STTouches returns 1.

Practice SQL

Open in SQL Flow

Open the SQL for a walkthrough. Run the example in SQL Server to check its result.

-- Planar geometry. SRID 0 coordinates here are synthetic units, not metres.
DECLARE @left geometry;
DECLARE @right geometry;
SET @left = geometry::STGeomFromText(N'POLYGON((0 0, 4 0, 4 4, 0 4, 0 0))', 0);
SET @right = geometry::STGeomFromText(N'POLYGON((4 0, 8 0, 8 4, 4 4, 4 0))', 0);
SELECT @left.STTouches(@right) AS share_boundary_only,
       @left.STSrid AS left_srid,
       @right.STSrid AS right_srid,
       @left.STIsValid() AS left_is_valid,
       @right.STIsValid() AS right_is_valid;

Open Microsoft Learn for full syntax, permissions, and details for your version.