-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathVersionHistoryIndex.sql
More file actions
28 lines (27 loc) · 959 Bytes
/
VersionHistoryIndex.sql
File metadata and controls
28 lines (27 loc) · 959 Bytes
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
--------------------------------------------------------------------------------------------------------------------------------
-- VERSION HISTORY (INDEX)
--------------------------------------------------------------------------------------------------------------------------------
-- Creates a list of the last five versions for every topic in the database. This is useful for basic version rollbacks, by
-- providing a list of recent versions that can be reverted to.
--------------------------------------------------------------------------------------------------------------------------------
CREATE
VIEW [dbo].[VersionHistoryIndex]
WITH SCHEMABINDING
AS
WITH TopicVersions
AS (
SELECT DISTINCT
TopicID,
Version,
RowNumber = ROW_NUMBER() OVER (
PARTITION BY TopicID
ORDER BY Version DESC
)
FROM [dbo].[Attributes]
GROUP BY TopicID,
Version
)
SELECT Versions.TopicId,
Version
FROM TopicVersions Versions
WHERE RowNumber <= 5