Last active
September 16, 2021 14:50
-
-
Save chilismaug/83ac49bde56b9acd9123a991f01e2bc7 to your computer and use it in GitHub Desktop.
Phil Factor's Hiearchy table declaration for JSON werx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Create the data type IF EXISTS (SELECT * FROM sys.types WHERE name LIKE 'Hierarchy') | |
DROP TYPE dbo.Hierarchy | |
go | |
/****** Object: UserDefinedTableType [dbo].[Hierarchy] Script Date: 4/14/2020 8:48:14 AM ******/ | |
CREATE TYPE [dbo].[Hierarchy] AS TABLE( | |
[element_id] [int] NOT NULL, /* internal surrogate primary key gives the order of parsing and the list order */ | |
[sequenceNo] [int] NULL, /* the place in the sequence for the element */ | |
[parent_ID] [int] NULL, /* if the element has a parent then it is in this column. The document is the ultimate parent, so you can get the structure from recursing from the document */ | |
[Object_ID] [int] NULL, /* each list or object has an object id. This ties all elements to a parent. Lists are treated as objects here */ | |
[NAME] [nvarchar](2000) NULL, /* the name of the object, null if it hasn't got one */ | |
[StringValue] [nvarchar](max) NOT NULL, /*the string representation of the value of the element. */ | |
[ValueType] [varchar](10) NOT NULL, /* the declared type of the value represented as a string in StringValue*/ | |
PRIMARY KEY CLUSTERED | |
( | |
[element_id] ASC | |
)WITH (IGNORE_DUP_KEY = OFF) | |
) | |
GO |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment