-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathTopicReferences.sql
29 lines (29 loc) · 1.11 KB
/
TopicReferences.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
--------------------------------------------------------------------------------------------------------------------------------
-- TOPIC REFERENCES (TABLE)
--------------------------------------------------------------------------------------------------------------------------------
-- Represents 1:1 relationship between topics, grouped together by namespaces ("ReferenceKey").
--------------------------------------------------------------------------------------------------------------------------------
CREATE
TABLE [dbo].[TopicReferences] (
[Source_TopicID] INT NOT NULL,
[ReferenceKey] VARCHAR(128) NOT NULL,
[Target_TopicID] INT NULL,
[Version] DATETIME2(7) NOT NULL DEFAULT SYSUTCDATETIME()
CONSTRAINT [PK_TopicReferences] PRIMARY KEY
CLUSTERED ( [Source_TopicID] ASC,
[ReferenceKey] ASC,
[Version] DESC
),
CONSTRAINT [FK_TopicReferences_Source]
FOREIGN KEY ( [Source_TopicID]
)
REFERENCES [dbo].[Topics] (
[TopicID]
),
CONSTRAINT [FK_TopicReferences_Target]
FOREIGN KEY ( [Target_TopicID]
)
REFERENCES [dbo].[Topics] (
[TopicID]
)
);