starsky51
MIS
- Mar 11, 2002
- 91
Morning All.
I've set up a table which self joins to form a heirarchical structure.
Simplified example of the table:
I have set up a UDF against the table to display the heirarchy of each record as a string:
and then added a computed column to the Assets table to use the function:
I would now like to index the computed column to save a few IO cycles but when i try the following:
i receive the error "Column 'Heirarchy' in table 'Assets' cannot be used in an index or statistics or as a partition key because it does user or system data access."
I don't really understand what it's getting at and neither does google.
Anyone got any ideas?
I've set up a table which self joins to form a heirarchical structure.
Simplified example of the table:
Code:
CREATE TABLE Assets
(
AssetID int IDENTITY(0,1) PRIMARY KEY CLUSTERED,
ParentAssetID int NOT NULL DEFAULT(0),
CONSTRAINT fk_Assets_ParentAssetID_AssetID FOREIGN KEY(ParentAssetID) REFERENCES Assets(AssetID),
);
I have set up a UDF against the table to display the heirarchy of each record as a string:
Code:
CREATE FUNCTION dbo.udfGetAssetHeirarchy(@AssetID int)
RETURNS varchar(100)
WITH SCHEMABINDING
AS
BEGIN
DECLARE @ParentID int;
DECLARE @Heirarchy varchar(100) = '';
SELECT @ParentID = ParentAssetID FROM dbo.Assets WHERE AssetID = @AssetID;
WHILE (@ParentID <> 0)
BEGIN
SET @Heirarchy = (@Heirarchy + '(' + CAST(@ParentID AS varchar) + ')');
SELECT @ParentID = ParentAssetID FROM dbo.Assets WHERE AssetID = @ParentID;
END
RETURN @Heirarchy;
END
and then added a computed column to the Assets table to use the function:
Code:
ALTER TABLE dbo.Assets ADD Heirarchy AS dbo.udfGetAssetHeirarchy([AssetID]);
I would now like to index the computed column to save a few IO cycles but when i try the following:
Code:
CREATE INDEX idxAssetsHeirarchy ON Assets(Heirarchy);
I don't really understand what it's getting at and neither does google.
Anyone got any ideas?