-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathAttributes.sql
50 lines (48 loc) · 2.1 KB
/
Attributes.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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
--------------------------------------------------------------------------------------------------------------------------------
-- ATTRIBUTES (TABLE)
--------------------------------------------------------------------------------------------------------------------------------
-- Provides the primary storage for topic attributes, including not only core identifiers such as Key, ContentType, and
-- ParentID, but additionally any other key/value pairs associated with a topic. This table limits values to 255 and is intended
-- for "indexed" attributes—i.e., attributes that are widely referenced and should be easy to access. Longer values, or those
-- only needed in narrow cases, should instead be store in the attribute AttributeXml.
--------------------------------------------------------------------------------------------------------------------------------
CREATE
TABLE [dbo].[Attributes] (
[TopicID] INT NOT NULL,
[AttributeKey] VARCHAR(128) NOT NULL,
[AttributeValue] NVARCHAR(255) NOT NULL,
[Version] DATETIME2(7) NOT NULL DEFAULT SYSUTCDATETIME()
CONSTRAINT [PK_Attributes] PRIMARY KEY
CLUSTERED ( [TopicID] ASC,
[AttributeKey] ASC,
[Version] DESC
),
CONSTRAINT [FK_Attributes_TopicID]
FOREIGN KEY ( [TopicID]
)
REFERENCES [dbo].[Topics] (
[TopicID]
)
);
GO
--------------------------------------------------------------------------------------------------------------------------------
-- CORE ATTRIBUTES (INDEX)
--------------------------------------------------------------------------------------------------------------------------------
-- Provides a filtered index of the core attributes needed to establish a topic entity—namely the Key, ContentType, and
-- ParentID.
--------------------------------------------------------------------------------------------------------------------------------
CREATE NONCLUSTERED
INDEX [IX_Attributes_AttributeKey]
ON [dbo].[Attributes] (
[TopicID] ASC,
[AttributeKey] ASC,
[Version] DESC
)
INCLUDE ( [AttributeValue]
)
WHERE ( [AttributeKey]
IN ( 'Key',
'ParentID',
'ContentType'
)
);