Understanding hierarchical data
Hierarchical data, as per the name, defines data items that are related to each other by a hierarchical relationship. When we think of hierarchical data, we get a visual of a tree in our mind and a root node and one or multiple leaves; in a relational database, it’s often referred to as a parent-child relation. Every child will have one parent and one parent can have one or multiple children.
Here are a few common examples of hierarchical data items in databases:
- Employee/manager relationship
- Organizational hierarchy
- Folder/files system
- Graph of links between web pages
- Tasks assigned under a project
MS SQL has a built-in data type, hierarchyid
, and it is specially designed to store and query hierarchical data and optimized for most common cases representing tree structure hierarchical data.
There are two ways to represent nodes in this data type—string and bit representation.
The /
character is used...