GetRoot (Database Engine)

Applies to: SQL Server Azure SQL Database Azure SQL Managed Instance

Returns the root of the hierarchy tree. GetRoot() is a static method.


-- Transact-SQL syntax  
hierarchyid::GetRoot ( )   
-- CLR syntax  
static SqlHierarchyId GetRoot ( )   


To view Transact-SQL syntax for SQL Server 2014 (12.x) and earlier versions, see Previous versions documentation.

Return Types

SQL Server return type:hierarchyid

CLR return type:SqlHierarchyId


Used to determine the root node in a hierarchy tree.


A. Transact-SQL example

The following example returns the root of the hierarchy tree:

SELECT OrgNode.ToString() AS Text_OrgNode, *  
FROM HumanResources.EmployeeDemo  
WHERE OrgNode = hierarchyid::GetRoot()  

B. CLR example

The following code snippet calls the GetRoot() method:


See also

hierarchyid Data Type Method Reference
Hierarchical Data (SQL Server)
hierarchyid (Transact-SQL)