A column of data type HIERARCHYID does not represent a tree or graph
automatically. It is up to you to assign values that represent the desired
relationship between nodes.
The HIERARCHYID data type does not prevent cyclic paths by itself. You can
easily simulate one:
CREATE TABLE Employees (
emp_id INT NOT NULL,
manager_id INT,
org_chart_path HIERARCHYID);
INSERT INTO Employees
VALUES (1, NULL, '/1/'),
(2, 1, '/1/2/'),
(3, 2, '/1/2/3/'),
(1, 3, '/1/2/3/1/');
You have to handle it via constraints. In the example below the PRIMARY KEY
will not allow cyclic occurrences:
CREATE TABLE Employees (
emp_id INT NOT NULL PRIMARY KEY,
manager_id INT REFERENCES Employees(emp_id),
org_chart_path HIERARCHYID);
This way the HIERARCHYID data type can be used to address problems that
involve cyclic graphs as well as tree structures.
HTH,
Plamen Ratchev
http://www.SQLStudio.com >> Stay informed about: Sql2008 HierarchyID