09.04.2013 Views

SNOMED CT® Release Format 1 (RF1) Guide - ihtsdo

SNOMED CT® Release Format 1 (RF1) Guide - ihtsdo

SNOMED CT® Release Format 1 (RF1) Guide - ihtsdo

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

346 | <strong>SNOMED</strong> CT <strong>Release</strong> <strong>Format</strong> 1 (<strong>RF1</strong>) <strong>Guide</strong> July 2012<br />

4.5.5.2.3. Generating a transitive closure table<br />

There are various ways in which a transitive closure table can be generated. The method illustrated here<br />

represents the smallest SQL query that might be used for this purpose. It is not the most efficient query and<br />

may take several hours to run. However, it does offer a simple standard for comparing the results of alternative<br />

approaches.<br />

Table 260: Sample SQL for Deriving a Transitive Closure Table<br />

-- Create simple sct_transitive closure table<br />

-- This version uses varchar for string ConceptId values<br />

-- An alternative would be to use bigint using the 64-bit integer representation<br />

CREATE TABLE [sct_transitiveclosure] (<br />

[SubtypeId] [varchar] (18) COLLATE Latin1_General_CI_AS NOT NULL ,<br />

[SupertypeId] [varchar] (18) COLLATE Latin1_General_CI_AS NOT NULL ,<br />

CONSTRAINT [PK_sct_transitiveclosure] PRIMARY KEY CLUSTERED<br />

(<br />

[SubtypeId]<br />

[SupertypeId],<br />

)<br />

)<br />

-- Add inverted index<br />

CREATE INDEX [IX_sct_transitiveclosure] ON [dbo].[sct_transitiveclosure]([SupertypeId])<br />

-- Initial row creation self reference<br />

INSERT INTO [sct_transitiveclosure]([SupertypeId], [SubtypeId])<br />

SELECT [ConceptId], [ConceptId] FROM [sct_concepts]<br />

-- Further row creation<br />

WHILE @@ROWCOUNT>0<br />

-- Repeats while new rows are created by the following query<br />

INSERT INTO [sct_transitiveclosure] ([SupertypeId], [SubtypeId])<br />

SELECT distinct [ConceptId2],[tc].[SubtypeId] FROM [sct_relationships] INNER JOIN [sct_transitiveclosure]<br />

as tc<br />

ON [ConceptId1]=[tc].[SupertypeId]<br />

LEFT OUTER JOIN [sct_transitiveclosure] As tc2<br />

ON [ConceptId2]=[tc2].[SupertypeId] AND [tc].[SubtypeId]=[tc2].[SubtypeId]<br />

WHERE [RelationshipType]='116680003' AND [tc2].[SubtypeId] is null<br />

© 2002-2012 International Health Terminology Standards Development Organisation CVR #: 30363434

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!