Skip to content

Instantly share code, notes, and snippets.

@jeremyrsellars
Created July 24, 2014 21:32
Show Gist options
  • Save jeremyrsellars/96e6d1fe12b8a6f2f2ac to your computer and use it in GitHub Desktop.
Save jeremyrsellars/96e6d1fe12b8a6f2f2ac to your computer and use it in GitHub Desktop.
Delete ClarityConnect placeholder records that have been superseded
use illuminatedb
go
-- note, it is possible for the placeholder hash to change with new versions of ClarityConnect, replace this where necessary.
select distinct NoteId
into #PublishedNoteIds
from Clarity.NoteVersion NV
inner join Clarity.PublishedNoteVersion PNV on PNV.NoteVersionId=NV.NoteVersionId AND NV.HeaderHash <> '89C4E5D1-4BC6-2C9F-9754-1270646437D0'
alter table #PublishedNoteIds ADD PRIMARY KEY (NoteID)
-- execute this until no rows are returned
declare @FirstPublished bigint
select top 1 @FirstPublished=NoteVersionId
from Clarity.PublishedNoteVersion PNV
order by NoteVersionId
delete top(1000000) NV
from Clarity.NoteVersion NV
inner join #PublishedNoteIds PNI on PNI.NoteId = NV.NoteId
where NV.HeaderHash = '89C4E5D1-4BC6-2C9F-9754-1270646437D0'
and NV.NoteVersionId < @FirstPublished
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment