-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathRelationships.sql
31 lines (31 loc) · 1.17 KB
/
Relationships.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
30
31
--------------------------------------------------------------------------------------------------------------------------------
-- HIERARCHY (TABLE)
--------------------------------------------------------------------------------------------------------------------------------
-- Represents n:n relationships between topics, grouped together by namespaces ("RelationshipKey").
--------------------------------------------------------------------------------------------------------------------------------
CREATE
TABLE [dbo].[Relationships] (
[Target_TopicID] INT NOT NULL,
[Source_TopicID] INT NOT NULL,
[RelationshipKey] VARCHAR(255) NOT NULL,
[IsDeleted] BIT NOT NULL DEFAULT 0,
[Version] DATETIME2(7) NOT NULL DEFAULT SYSUTCDATETIME()
CONSTRAINT [PK_Relationships] PRIMARY KEY
CLUSTERED ( [Source_TopicID] ASC,
[RelationshipKey] ASC,
[Target_TopicID] ASC,
[Version] DESC
),
CONSTRAINT [FK_Relationships_Source]
FOREIGN KEY ( [Source_TopicID]
)
REFERENCES [dbo].[Topics] (
[TopicID]
),
CONSTRAINT [FK_Relationships_Target]
FOREIGN KEY ( [Target_TopicID]
)
REFERENCES [dbo].[Topics] (
[TopicID]
)
);