I have a SQL Server database which includes a Users
table with the following columns:
- UserId: nvarchar(128)
- email: nvarchar(256)
- ...
I want to add a users hierarchy to my system. This means, one user will be the "administrator". Other will be the children of the administrator or other users.
So, I thought of adding a new column:
- ParentUser: hierarchyid
to the Users
table. The administrator user will be the top level value of hierarchy. Other will be placed below it. For example:
\b2566df8-9129-405b-a0e6-a56da3b49c5a\79336162-022e-495c-8655-64de1abe556c
\admin-id\normal-user-id
My problem is that hierarchyid column doesn't accept nvarchar(128)
(my user-id) as valid value. So, my administator user cannot get the value "\b2566df8-9129-405b-a0e6-a56da3b49c5a" in his [ParentColumn]
.
The error I get when I use SQL Server Management Studio:
Tried those values:
- b2566df8-9129-405b-a0e6-a56da3b49c5a
- /b2566df8-9129-405b-a0e6-a56da3b49c5a
One possible solution is to create another unique id for each user. But, now create a userid which will be accepted by hierarchyid column. But, I want to avoid this solution and use the original user id.
How to solve this?